题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
#include <bits/stdc++.h>
using namespace std;
bool isZiShouShu(int num){
int tmp = num * num;
string s1 = to_string(num);
string s2 = to_string(tmp);
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
//cout << s1 << "," << s2 << endl;
int i = 0;
while(i < s1.size()){
if(s1[i] != s2[i]){
return false;
}
i++;
}
return true;
}
int main(){
int n = 0;
while(cin >> n){
int res = 0;
for(int i = 0; i <= n; i++){
if(isZiShouShu(i)) res++;
}
cout << res << endl;
}
return 0;
}
华为题库题解 文章被收录于专栏
牛客华为题库的题解

