AcWing 1346. 回文平方[ 枚举 ]
原题链接
简单
作者:
Value
,
2021-02-08 21:27:37
,
所有人可见
,
阅读 314
暴力枚举
#include <iostream>
#include <algorithm>
using namespace std;
string change(int n, int t){
string res = "";
while(n){
int num = n % t;
if(num < 10) res += (num + '0');
else res += (num - 10 + 'A');
n /= t;
}
reverse(res.begin(), res.end());
return res;
}
bool check(string str){
string tmp = str;
reverse(tmp.begin(), tmp.end());
return tmp == str;
}
int main(){
int n; cin >> n;
for(int i = 1; i <= 300; i ++ ){
string res = change(i * i, n);
if(check(res)) cout << change(i, n) << ' ' << res << endl;
}
return 0;
}