标签:
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; }
Section 1.2.4 Palindromic Squares 大水
标签:
原文地址:http://www.cnblogs.com/bbbbbq/p/4631734.html