题解 | #水仙花数#
水仙花数
http://www.nowcoder.com/practice/11c9f023a9f84418a15b48792a5f7c70
c++代码: 在input模块不能用while(cin)不知道为什么感觉是牛客的bug,要是有人知道麻烦解释一下
#include #include using namespace std; vector find_num(int min, int max) { vector temp; for (int i = min; i <= max; i++) { int temp1 = i % 10; int temp10 = ((i - temp1) % 100)/10; int temp100 = i / 100; if (temp1temp1temp1 + temp10 * temp10temp10 + temp100 * temp100temp100 == i)temp.push_back(i); } return temp; } void input_find_num() { int min, max; while (scanf("%d%d", &min, &max) != EOF) { vector num; num.clear(); num = find_num(min, max); if (num.size() == 0)cout << "no" << endl; else { for (int i = 0; i < num.size(); i++) { cout << num[i] << " "; } cout << endl; } } } int main() { input_find_num();
}