HDU 2010 (水)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2010

题目大意:给你段连续的数,把满足条件(数字 每一位的3 == 该数字)的数输出,就是水仙花数

解题思路:

很水,考察取余数(%)的基本运用

代码:

 1 #include<iostream>
 2 #include<cmath>
 3 //#include<cstdio>
 4 #include<iomanip>
 5 //#include<algorithm>
 6 using namespace std;
 7 int main()
 8 {
 9     int m, n;
10 
11 ////    int a = pow(5, 2);
12 //    double a = pow(5, 2);
13 //    cout << a << endl;
14 
15     while(cin >> m >> n)
16     {
17         int p = 0;
18         for(int i = m; i <= n; i ++)
19         {
20             if(pow(i % 10, 3) + pow(i / 10 % 10, 3) + pow (i / 100, 3) == i)
21             {
22                 if(p == 0)
23                     cout << i;// << endl;
24                 else 
25                     cout << ' ' << i ;//<< endl;
26                 p = 1;
27             }
28         }
29         if(p == 1)
30             cout << endl;
31         if(p == 0)
32             cout << "no" << endl;
33     }
34 }

猜你喜欢

转载自www.cnblogs.com/mimangdewo-a1/p/9368561.html
今日推荐