题解 | #自守数#
自守数
http://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = Integer.valueOf(scan.nextLine().trim());
int ans = 0;
for (int i = 0; i <= n; i++) {
if (isValid(i)) {
ans++;
}
}
System.out.println(ans);
}
public static boolean isValid(int num) {
String str1 = num * num + "";
String str2 = String.valueOf(num);
return str1.substring(str1.length() - str2.length()).equals(str2);
}
}