题解 | #自守数#

自守数

https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e

倒着往回数 来一一匹配

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        let n = parseInt(line);
        let sum_zishoushu = 0
        for(let i=0; i<=n; i++){
            let str_i = i.toString().split('');
            let str_ii = (i*i).toString().split('');
            let flag = true;
            for(let j=0;j<str_i.length;j++){ //倒着往回数
                if(str_i[str_i.length-1-j] != str_ii[str_ii.length-1-j]){
                    flag = false;
                    break;
                }
            }
            if(flag) sum_zishoushu++;
        }
        console.log(sum_zishoushu);
    }
}()

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务