题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
import java.util.Scanner;
public class Main {
public static int fun(int num) {
String str1 = "";
String str2 = "";
String temp = "";
int count = 0;
for (int i = 0; i <= num; i++) {
str1 = Integer.toString(i);
temp = Integer.toString(i * i);
str2 = temp.substring(temp.length() - str1.length());
if (str1.equals(str2)) {
count += 1;
}
}
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int res = fun(n);
System.out.print(res);
}
}
查看18道真题和解析