Palsquare Problem Solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
In the 1~300, the square in the B-system is the number of palindrome number to output. Each number x outputs a row, and the X and x ² in the output B are separated by a space.
Note that these numbers, 10~19, are denoted by capital letters ' A ', ' B ', and so on.
"Data Range"
1<=b<=20
"Input Sample"
10
"Output Example"
1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
There is no difficulty in making the conversion.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
The binary conversion made a small mistake, and the output was cout from the beginning.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Code
1 /*2 id:icedrea13 Prob:palsquare4 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten One intB; A Charto[ -]={'0','1','2','3','4','5','6','7','8','9', - 'A','B','C','D','E','F','G','H','I','J' }; - the stringChangeintx) - { - stringnum; - while(x) {num=to[x%b]+num; x/=B;} + returnnum; - } + A BOOLIspal (intx) at { - stringNum=change (x*x); - for(intI=0; I!=num.size (); + +i) - if(Num[i]!=num[num.size ()-1-I.])return false; - return true; - } in - intMain () to { +Ifstreaminch("palsquare.in"); -Ofstream out("Palsquare.out"); the * inch>>B; $ for(intI=1; i<= -;++i)Panax Notoginseng { - if(!ispal (i))Continue; the out<<change (i) <<" "<<change (i*i) <<Endl; + } A the inch. Close (); + out. Close (); - return 0; $}
Usaco Section1.2 palindromic squares Problem Solving Report