http://www.wzoi.org/usaco/12%5C501.asp
patpat 学习了一个新的stl函数
eg.
string poi = "poi";
reverse(poi.begin(), poi.end());
就把poi变成了"iop"
#include <bits/stdc++.h> using namespace std; int base; string trans(int temp){ int j, ch; string ans = ""; while(temp){ ch = temp % base; if(ch < 10) ans += ch + ‘0‘; else ans+= ch - 10 +‘A‘; temp /= base; } return ans; } int main() { #ifndef poi freopen("palsquare.in","r",stdin); freopen("palsquare.out","w",stdout); #endif string str; scanf("%d", &base); int i, temp, j, ch, len; for(i = 1; i <= 300; i++){ str = trans(i * i); len = str.length(); for(j = 0; j <= len / 2; j++){ if(str[j] != str[len - j - 1]) break; } if(j <= len / 2) continue; string tp = trans(i);reverse(tp.begin(), tp.end()); cout<<tp<<" "<<str<<endl; } return 0; }
时间: 2024-10-13 05:03:20