题解 | 输出水仙花数
#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; }