zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    【POJ
    【POJ
    【POJ
    【POJ
    【POJ
    【POJ
    【POJ
    【POJ
    NAT
    OSPF与ACL综合实验
  • 原文地址:https://www.cnblogs.com/gerjcs/p/9368561.html
Copyright © 2011-2022 走看看