题解 | 对称平方数
对称平方数
https://www.nowcoder.com/practice/1b79865e2f534db0adba84dca10d6bae
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
//对称有两种情况,1是无对称轴数,如1221,2是有对称轴数,如13231
//给出思路,用to_string将int变为字符串,随后用reverse反转,然后比较反转前后的字符串
int main() {
for(int n=1;n<=256;n++)
{
int p=n*n;
string str=to_string(p);
string c=str;
reverse(str.begin(),str.end());
if(c==str)
cout<<n<<endl;
}
}
// 64 位输出请用 printf("%lld")
会用reverse(it,it)就简单
