题解 | #自守数#
自守数
http://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int count = 0;
for (int i = 0; i <= n; i++) {
if(isOK(i)){
count++;
}
}
System.out.println(count);
}
}
private static boolean isOK(int i) {
if(i == 0 || i == 1){
return true;
}
String sNew = i * i + "";
String s = i + "";
int sLen = s.length();
int sNewLen = sNew.length();
if(sNew.substring(sNewLen - sLen).equals(s)){
return true;
}
return false;
}
}