题解 | 变种水仙花

变种水仙花

https://www.nowcoder.com/practice/c178e3f5cc4641dfbc8b020ae79e2b71

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

bool F(int a){
    string s=to_string(a);
    int t = s.length()-1;
    int n=0;
    while (t) {
        n+=stoi(s.substr(0,t))*stoi(s.substr(t));
        t--;
    }
    if (n==a) {
        return true;
    }else {
        return false;
    }
}

int main() {
    vector<int> vec;
    for (int i=10000; i<=99999; i++) {
        if (F(i)) {
            vec.push_back(i);
        }
    }
    for(auto u:vec)
    cout<<u<<" ";
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论
虽然是暴力解,但是好在没超时
点赞 回复 分享
发布于 03-12 20:39 河南

相关推荐

政委qqq:这道题在算法竞赛里唯一考的就是高精度,但是只能难住C++这类语言,Python直接a+b秒天秒地
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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