题解 | #输出水仙花数#
输出水仙花数
http://www.nowcoder.com/practice/dabaf13009ef4d0cbf22302fd6a530a6
using namespace std;
bool Nacissistic(int num){
//血泪教训 num是变量 需要再定义一个常量对其原来值进行判断
int t = num;
int a = num % 10;
num /= 10;
int b = num % 10;
num /= 10;
int c = num % 10;
if (t == a*a*a + b*b*b + c*c*c)
return true;
else
return false;
}
int main() {
int num;
for (num = 100; num <= 999; num++){
if (Nacissistic(num)){
cout << num << endl;
}
}
return 0;
}