题解 | #自守数#__huawei_no.99-1
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
long a ;
while (cin >> a) {
int count = 0;
for (int i = 0 ; i <= a; i++) {
int temp = i;
long b = temp * temp;
string str_a = to_string(temp);
string str_b = to_string(b);
reverse(str_a.begin(), str_a.end());
reverse(str_b.begin(), str_b.end());
if (str_b.substr(0, str_a.size()) == str_a) {
count++;
}
}
cout << count;
}
return 0;
}
// 64 位输出请用 printf("%lld")
完全原创的方法,非常棒。

查看14道真题和解析