题解 | 输出水仙花数

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

int main() {
    
    // write your code here......
    for (int i = 100; i <= 999; i ++) {
        string temp = to_string(i);
        int bai = temp[0] - '0';
        int shi = temp[1] - '0';
        int ge = temp[2] - '0';
        int bai3 = bai*bai*bai;
        int shi3 = shi*shi*shi;
        int ge3 = ge*ge*ge;
        if (i == (bai3 + shi3 + ge3)) {
            cout << i << endl;
        }
    }
    

    return 0;
}

全部评论

相关推荐

07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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