hdu2010

水仙花数

http://acm.hdu.edu.cn/showproblem.php?pid=2010

   1 #include<stdio.h>
   2 int main()
   3 {int n,m,t,i,j,ge,shi,bai,flag,sum,a[10] ;
   4     while(scanf("%d%d",&n,&m)!=EOF)
   5          {if(m>n){t=m;m=n;n=t;}
   6          if(m<100||n>999) continue;
   7             flag=0;j=0;
   8          for(i=m;i<=n;i++)
   9             {t=i;
  10              ge=t%10;
  11              t=t/10;shi=t%10;
  12              bai=t/10; sum=ge*ge*ge+shi*shi*shi+bai*bai*bai;
  13              if(i==sum) {a[j]=i;j++;flag=1;}
  14             }
  15           if(flag==0) printf("no\n");
  16              else {printf("%d",a[0]);
  17                    for(i=1;i<j;i++)
  18                       printf(" %d",a[i]);
  19                    printf("\n");
  20               }
  21          }
  22 }

hdu2010 (2008-06-02 12:32:49由czk编辑)