题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
/*
25
5
*/
bool compare_num(string a, string b) {
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int n = a.size();
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
return false;
}
}
return true;
}
int main() {
int n;
cin >> n;
int n_2;
int res = 0;
for (int i = 0; i <= n; i++) {
n_2 = pow(i, 2);
if (compare_num(to_string(i), to_string(n_2))) {
res++;
}
}
cout << res;
}
// 64 位输出请用 printf("%lld")
不聪明
#华为OD机试真题#
查看12道真题和解析