题解 | #水仙花数#

水仙花数

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

#include <iostream>
using namespace std;

bool isNarcissisticNumber(int num) {
    int hundreds = num / 100;
    int tens = (num % 100) / 10;
    int units = num % 10;
    return (hundreds * hundreds * hundreds + tens * tens * tens + units * units * units == num);
}

int main() {
    int m, n;
    while (cin >> m >> n) {
        bool found = false;
        for (int i = m; i <= n; i++) {
            if (isNarcissisticNumber(i)) {
                cout << i << " ";
                found = true;
            }
        }
        if (!found) {
            cout << "no";
        }
        cout << endl;
    }
    return 0;
}

全部评论

相关推荐

07-04 16:00
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-28 22:48
已编辑
广东金融学院 Java
小浪_Coding:学院本+这俩项目不是buff叠满了嘛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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