题解 | #自守数#
自守数
http://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
int count = 0;
for(int i = 0; i<=num; i++){
int k = i*i;
int flag =0;
int n = i;
while( n!=0 ){
if( n%10 == k%10 ){ n = n/10; k = k/10; continue; }
else { flag =1; break;}
}
if( flag == 0){ count++; }
}//for_i
System.out.print(count);
}
}
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
int count = 0;
for(int i = 0; i<=num; i++){
int k = i*i;
int flag =0;
int n = i;
while( n!=0 ){
if( n%10 == k%10 ){ n = n/10; k = k/10; continue; }
else { flag =1; break;}
}
if( flag == 0){ count++; }
}//for_i
System.out.print(count);
}
}