USER: tianbing tianbing [tbbd4261]
TASK: palsquare
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 2928 KB]
Test 2: TEST OK [0.000 secs, 2928 KB]
Test 3: TEST OK [0.011 secs, 2928 KB]
Test 4: TEST OK [0.022 secs, 2928 KB]
Test 5: TEST OK [0.011 secs, 2928 KB]
Test 6: TEST OK [0.011 secs, 2928 KB]
Test 7: TEST OK [0.011 secs, 2928 KB]
Test 8: TEST OK [0.011 secs, 2928 KB]
All tests OK.
Your program ('palsquare') produced all correct answers! This is your
submission #3 for this problem. Congratulations!
Here are the test data inputs:
------- test 1 -------
10
------- test 2 -------
2
------- test 3 -------
5
------- test 4 -------
11
------- test 5 -------
15
------- test 6 -------
18
------- test 7 -------
20
------- test 8 -------
3
Keep up the good work!
Thanks for your submission!
代码:
WA了两次,第一次B>=10的话没有转变成对应的字母,第二次忘了换成文件 加油!
1/**//*
2ID:tbbd4261
3LANG:C++
4PROG:palsquare
5*/
6#include<iostream>
7#include<algorithm>
8#include<string>
9#include<vector>
10#include<fstream>
11using namespace std;
12string pal(int n,int base,bool &flag)
13{
14 string str="";
15 while(n)
16 {
17 str+=(n%base>=10)?n%base-10+'A':n%base+'0';
18 n=n/base;
19 }
20 for(int i=0,j=str.size()-1; i<str.size()/2;i++,j--)
21 if(str[i]!=str[j]){ flag=0; break;}
22 reverse(str.begin(),str.end());
23 return str;
24}
25string turn(int n,int base)
26{
27 string str="";
28 while(n)
29 {
30 str+=(n%base>=10)?n%base-10+'A':n%base+'0';
31 n=n/base;
32 }
33 reverse(str.begin(),str.end());
34 return str;
35}
36int main()
37{
38 ifstream fin("palsquare.in");
39 ofstream fout("palsquare.out");
40 int base,i; string str;
41 fin>>base;
42 for(i=1; i<=300; i++)
43 {
44 bool flag=1;
45 string s1=turn(i,base);
46 string s2=pal(i*i,base,flag);
47 if(flag) { fout<<s1<<' '<<s2<<endl; }
48 }
49
50 //system("pause");
51 return 0;
52}
53