解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了。
1 #include<cstdio> 2 #include<string> 3 #include<cstring> 4 #include<map> 5 #include<iostream> 6 using namespace std; 7 int trans(int x,int r) { 8 int sum = 0; 9 while(x) { 10 sum += x%r; 11 x/=r; 12 } 13 return sum; 14 } 15 16 int main() { 17 int n; 18 while(scanf("%d",&n),n) 19 if(trans(n,10) == trans(n,16) && trans(n,16) == trans(n,12)) 20 printf("%d is a Sky Number. ",n); 21 else printf("%d is not a Sky Number. ",n); 22 return 0; 23 }