zoukankan      html  css  js  c++  java
  • Palindromic Squares 回文平方数

    1.2.4 Palindromic Squares 回文平方数

    Time Limit: 1 Sec  Memory Limit: 64 MB
    Submit: 139  Solved: 66
    [Submit][Status][Forum]

    Description

    回文数是指从左向右念和从右向左念都一样的数。如12321就是一个典型的回文数。 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且它的平方用B进制表示时是回文数的数。用’A’,’B’……表示10,11等等。

    Input

    共一行,一个单独的整数B(B用十进制表示)。

    Output

    每行两个B进制的符合要求的数字,第二个数是第一个数的平方,且第二个数是回文数。

    Sample Input

    10 

    Sample Output

    1 1
    2 4
    3 9
    11 121
    22 484
    26 676
    101 10201
    111 12321
    121 14641
    202 40804
    212 44944
    264 69696


    主要是通过这个题复习一下进制转换。除此之外,认真审题,看看题目让你输出的是什么!!!

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<stack>
     9 #include<deque>
    10 #include<map>
    11 #include<iostream>
    12 using namespace std;
    13 typedef long long  LL;
    14 const double pi=acos(-1.0);
    15 const double e=exp(1);
    16 const int N = 10009;
    17  
    18 int n;
    19 char con[1000];
    20  
    21 int judge(int k)
    22 {
    23     int i,p,j;
    24     for(i=0; i<=(k-1)/2; i++)
    25     {
    26         if(con[i]!=con[k-i])
    27             break;
    28     }
    29     if(i>(k-1)/2)
    30         return 1;
    31     return 0;
    32 }
    33  
    34 int to(int k)    //进制转换
    35 {
    36     int i,p=-1,j;
    37     int x=k;
    38     while(x)
    39     {
    40         j=x%n;
    41         x/=n;
    42         if(j>=10)
    43             con[++p]=65+j-10;
    44         else
    45             con[++p]=j+48;
    46     }
    47     con[++p]=0;
    48     return p-1;
    49 }
    50  
    51 int main()
    52 {
    53     int i,p,j;
    54     scanf("%d",&n);
    55     printf("1 1
    ");
    56     for(i=2; i<=300; i++)
    57     {
    58         p=to(i*i);
    59         if(judge(p))
    60         {
    61             p=to(i);
    62             for(j=p;j>=0;j--)
    63                 printf("%c",con[j]);
    64             putchar(' ');
    65             p=to(i*i);
    66             for(j=p;j>=0;j--)
    67                 printf("%c",con[j]);
    68             putchar('
    ');
    69         }
    70     }
    71  
    72  
    73     return 0;
    74 }
    View Code
  • 相关阅读:
    printf函数实现的深入剖析
    rhel/centos播放mp3文件
    GRUB(GRand Unified Boot loader)引导加载程序
    NAT DHCP WWW rc.local
    论文 毕业设计 相关 用语 评语
    Linux禁止单用户模式(single)来增强系统安全
    Kernel command using Linux system calls
    GNU-ld链接脚本浅析
    AT&T汇编心得之间接寻址和LEA指令
    Linux 汇编语言开发指南
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9694964.html
Copyright © 2011-2022 走看看