题解 | #自守数#

自守数

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);
    }
}

全部评论

相关推荐

移动云能力 苏小妍 总包多3w左右
点赞 评论 收藏
转发
头像
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务