1139: 水仙花数

题目描述

打印出所有"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该本身。例如:153是一个水仙花数,因为153=13+53+33。 Output:

153

???

???

???

输入

输出

所有的水仙花数,从小的开始。每行一个

AC代码

#include <iostream>
#include <math.h>
using namespace std;

int main() {
    for (int i = 100; i < 1000; i++) {
        int unit = i % 10;//个位
        int decade = i / 10 % 10;//十位
        int hundre = i / 100 % 10;//百位
        if (pow(unit, 3) + pow(decade, 3) + pow(hundre, 3) == i) cout << i << endl;
    }
posted @ 2023-02-19 14:21  我爱OJ  阅读(24)  评论(0)    收藏  举报  来源