题解 | #自守数#__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")

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

全部评论

相关推荐

自来熟的放鸽子能手面...:这个不一定,找hr跟进一下
点赞 评论 收藏
分享
故事和酒66:假设一下,就算报了培训班,不还是要投简历,只是项目改了。那不如先写几个培训班的项目,纯靠编,然后试试有没有面试。如果真有再报也不迟,如果没有还是没有,那就不是培训班的问题了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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