题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703?tpId=182&tqId=34793&ru=/exam/oj
//本文是在水仙花数大佬基础上改动的,因为目前的题解没有跳出程序的出口,出现死循环。
//故做了改动如下:
#include<iostream>
using namespace std;
int main() {
int i, m, n;
int a, b, c, num = 0;
while (true) {
cin >> m >> n;
for (i = m; i <= n; i++) {
a = i / 100;
b = i / 10 % 10;
c = i % 10;
if (i == a * a * a + b * b * b + c * c * c) {
cout << i << " ";
num++;
}
}
if (num == 0) {
cout << "no" << endl;
break;
}
else {
cout << endl;
break;
}
}
system("pause");
return EXIT_SUCCESS;
}
查看12道真题和解析