这里有个讲解 string 用法非常详细的博文:https://www.byvoid.com/zhs/blog/cpp-string
题目意思很简单啦,就是找回文
使用string可以高速A过
Source code:
/*
ID: wushuai2
PROG: palsquare
LANG: C++
*/
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x))) using namespace std;
const int INF = 0x3f3f3f3f; string solve(int base, int n){
string ss;
while(n){
if(n % base > ){
ss.push_back(n % base - + 'A');
} else{
ss.push_back(n % base + '');
}
n /= base;
}
reverse(ss.begin(), ss.end());
return ss;
} bool judge(string ss){
string pp = ss;
reverse(ss.begin(), ss.end());
if(ss.compare(pp) == ){
return true;
}
return false;
} int main() {
ofstream fout ("palsquare.out");
ifstream fin ("palsquare.in");
int base;
fin >> base;
for(int i = ; i <= ; ++i){
if(judge(solve(base, i * i))){
fout << solve(base, i) << ' ' << solve(base, i * i) << endl;
} } return ;
}