zoukankan      html  css  js  c++  java
  • 水仙花数

    #include <stdio.h>
    #include <math.h>
    // 算法竞赛的目标是编程对任意输入均得到正确的结果。
    // 请先独立完成,如果有困难可以翻阅本书代码仓库中的答案,但一定要再次独立完成。
    // “抓住主要矛盾”——始终把学习、实验的焦点集中在最有趣的部分。如果直观地解决方案行得通,就不必追究其背后的原理。
    
    /**
    【题目】水仙花数(daffodil)
    输出100~999中的所有水仙花数。若3位数ABC满足ABC=A^3 +B^3 +C^3 ,则称其为水仙花
    数。例如153=1^3 +5^3 +3^3 ,所以153是水仙花数。
    */
    
    
    /**
    【分析】循环计算出所有的水仙花数
    */
    
    
    int main()
    {
        int i;
        for (i=100;i<=999;i++) {
           int a,b,c;
           a = (i/100)%10;
           b = (i/10)%10;
           c = i%10;
           if (i == pow(a,3) + pow(b,3) + pow(c,3)) {
                printf("%d
    ",i);
           }
        }
    
        return 0;
    }
    
    
    
  • 相关阅读:
    P2610 [ZJOI2012]旅游
    P2323 [HNOI2006]公路修建问题
    P3629 [APIO2010]巡逻
    ARC059F
    AGC004D Teleporter
    p3203 弹飞绵羊
    bzoj5450 轰炸
    bzoj4313 三维积木
    cf123E Maze
    bzoj4423 [AMPPZ2013]Bytehattan
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/8515227.html
Copyright © 2011-2022 走看看