http://acm.hdu.edu.cn/showproblem.php?pid=2097
解法同1197,输出有些不一样而已
View Code
1 #include <stdio.h> 2 int main() 3 { 4 int i, n, sum10, sum12, sum16,a[10000]; 5 for (i=1000; i<10000; i++){ 6 n = i; 7 sum10 = 0; 8 while (n){ 9 sum10 += n%10; 10 n /= 10; 11 } 12 n = i; 13 sum12 = 0; 14 while (n){ 15 sum12 += n%12; 16 n /= 12; 17 } 18 n = i; 19 sum16 = 0; 20 while (n){ 21 sum16 += n%16; 22 n /= 16; 23 } 24 if (sum10==sum12 && sum12==sum16) 25 a[i]=1; 26 else a[i]=0; 27 } 28 while(scanf("%d",&n)&&n) 29 if(a[n]) 30 printf("%d is a Sky Number.\n",n); 31 else printf("%d is not a Sky Number.\n",n); 32 return 0; 33 }