题解 | #自守数#__huawei_no.99-1

自守数

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

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    long a ;
    while (cin >> a) {
        int count = 0;    
        for (int i = 0 ; i <= a; i++) {
            int temp = i;
            long b = temp * temp;
            string str_a = to_string(temp);
            string str_b = to_string(b);
            reverse(str_a.begin(), str_a.end());
            reverse(str_b.begin(), str_b.end());
            if (str_b.substr(0, str_a.size()) == str_a) {
                count++;
            }
        }
        cout << count;
    }

    return  0;

}
// 64 位输出请用 printf("%lld")

完全原创的方法,非常棒。

全部评论

相关推荐

牛客98820962...:个人意见,我觉得实习和项目经历要一致,达美乐感觉没必要写
点赞 评论 收藏
分享
01-29 15:45
已编辑
华中科技大学 前端工程师
COLORSN:可以试一下,小厂看技术栈是不是很落后,如果太拉胯就别去,个人认为有实习氛围比你自己琢磨要高效不少,然后就是小厂其实也有可能会问的很难,这都比较难说,还是看自己项目含金量够不够,寒假还能不能推进学习再选择,毕竟去实习过年就10天假了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务