题解 | #输出水仙花数#
输出水仙花数
https://www.nowcoder.com/practice/dabaf13009ef4d0cbf22302fd6a530a6
#include <iostream> using namespace std; int calCube(int v) { return v*v*v; } bool isTargetValue(int v) { if (v<100 || v>999) return false; int geWei = v % 10; int shiWei = (v / 10) % 10; int baiWei = v/100; if (calCube(geWei)+calCube(shiWei)+calCube(baiWei) == v) return true; return false; } int main() { // write your code here...... for (int i=100; i<1000; i++) { if (isTargetValue(i)) { cout << i << endl; } } return 0; }