zoukankan      html  css  js  c++  java
  • 2010

    水仙花数

    三位数的个 十 百 位的立方和等于三位数自己的数

     1 #include <stdio.h>
     2 
     3 int main()
     4 {
     5     int m, n,i,j,a,b,c;
     6     while (scanf_s("%d %d",&m,&n))
     7     {
     8         for (j = 0,i = m;i <=n;i++)
     9         {
    10             a = i / 100;
    11             b = i / 10 % 10;
    12             c = i % 10;
    13             
    14             if (a*a*a + b*b*b + c*c*c == i)
    15             {
    16                 printf("%d ",i);
    17                 j++;
    18             }
    19         }
    20         if (j == 0)
    21             printf("no answer");
    22         printf("
    ");
    23     }
    24 }

    参考答案

    1-1000只有5个水仙花数:1 153 370 371 407

     1 #include<stdio.h>
     2 
     3 int main()
     4 {
     5     int b, l, c, i;
     6     int a[] = {1, 153, 370, 371, 407};
     7 
     8     while (scanf("%d%d", &b, &l) != EOF)
     9     {
    10         c = 0;
    11         for (i = 0 ; i < 5 ; i++)
    12         {
    13             if (a[i] >= b && a[i] <= l)
    14                 printf(c++ ? " %d" : "%d", a[i]);
    15         }
    16         printf(c ? "
    " : "no
    ");
    17     }
    18 
    19     return 0;
    20 }
    ========================if i have some wrong, please give me a message, thx.========================
  • 相关阅读:
    macOS 修改键盘重复按键延迟
    stdout 与 stderr 区别
    E. 1-Trees and Queries
    Codeforces Round #615 (Div. 3)
    Codeforces Round 613(div 2)
    Codeforces Edu80
    SPOJ
    快读
    《货车运输》题解--最大生成树&倍增
    倍增思想求lca
  • 原文地址:https://www.cnblogs.com/ailx10/p/5327764.html
Copyright © 2011-2022 走看看