I'll tell you the conversion. I forgot that I had the digital logic textbook in mind.
/*id:modengd1prog:palsquarelang:c++*/#include <iostream> #include <stdio.h> #include <string.h># Include <stack>using namespace Std;char leter[20]={' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J '};//conversion, convert x into a string representation of the number of base binary in the Out array void changethebase (int x,int Base,char out[60]) {stack <char> S; int i=0; while (x>0) {s.push (leter[x%base]); X/=base; } for (i=0;! S.empty (); i++) {out[i]=s.top (); S.pop (); } out[i]=0;} Detects if a string ending with ' \ ' is not a palindrome string bool Ispalindromic (char input[60]) {int temp[60]; int Len=strlen (input); for (int i=0;i<len;i++) {temp[len-i-1]=input[i]; } for (int i=0;i<len;i++) {if (Input[i]!=temp[i]) return false; } return true; int main () {freopen ("palsquare.in", "R", stdin); Freopen ("Palsquare.out", "w", stdout); int square[301],base; scanf ("%d", &base); for (int i=1;i<=300;i++) {CHar out1[60],out2[60]; Changethebase (I,BASE,OUT1); Changethebase (I*I,BASE,OUT2); if (Ispalindromic (Out2)) {cout<<out1<< ' <<out2<<endl; }} return 0;}
Usaco palindromic Squares