HDU ACM 11 2010 水仙花数

来源:互联网 发布:淘宝整点秒杀 编辑:程序博客网 时间:2024/06/06 07:38
#include <iostream>using namespace std;int main(){int m, n, i = 0;while (cin >> m >> n){int temp;if (m > n){temp = m;m = n;n = temp;}while (m <= n){bool Lu = true;int a = m/100;int b = m/10%10;int c = m%10;if ( m == a*a*a + b*b*b + c*c*c){if (Lu){cout << m;Lu = false;}elsecout << " " << m;i++;}m++;}if (i == 0)cout << "no\n";elsecout << endl;i = 0;}return 0;}

以上为通过HDU答案。但咱感觉对的答案是下面那个
#include <iostream>using namespace std;int main(){int m, n, i = 0;while (cin >> m >> n){int temp;if (m > n){temp = m;m = n;n = temp;}while (m <= n){bool Lu = true;int a = m/100;int b = m/10%10;int c = m%10;if ( m == a*a*a + b*b*b + c*c*c){if (Lu){cout << m << " ";Lu = false;}elsecout << " " << m;i++;}m++;}if (i == 0)cout << "no\n";elsecout << endl;i = 0;}return 0;}


0 0
原创粉丝点击