数据加载中……

USACO 1.2.4 Palindromic Squares

把题目意思翻译成代码就行了。
 1 /*
 2 ID:31440461
 3 PROG:palsquare
 4 LANG:C++
 5 */
 6 #include<iostream>
 7 using namespace std;
 8 int B;
 9 const
10   int MAX=300;
11   char CH[20]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
12 
13 void printdata(int x)
14 {
15   int a[30],i=0;
16   while (x) a[++i]=x%B,x/=B;
17   for (;i;cout<<CH[ a[i--] ]);
18 }
19 
20 void handle( int x )
21 {
22   int a[30],n=0,xx=x*x;
23   while (xx)a[++n]=xx%B,xx/=B;
24   int t=n;
25   for (;(n)&&(a[n]==a[t-n+1]);--n);
26   if (n==0) printdata(x),cout<<' ',printdata(x*x),cout<<endl;
27 }
28 
29 int main()
30 
31   freopen("palsquare.in","r",stdin);
32   freopen("palsquare.out","w",stdout);
33   cin>>B;
34   for (int i=1;i<=MAX;i++) handle(i);
35   return 0;
36 }
37 


posted on 2009-07-12 13:39 Chen Jiecao 阅读(161) 评论(0)  编辑 收藏 引用 所属分类: USACO


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理