标签:
主要考察进制转换
Description
Input
如果为0,则输入结束。
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<cstdlib> 6 #include<algorithm> 7 using namespace std; 8 9 int main() 10 { 11 int x,t,n,i,b; 12 char a[100]; 13 char c[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 14 while(cin>>n&&n!=0) 15 { 16 int cnt=0; 17 cnt+=n/1000;cnt+=((n/100)%10);cnt+=((n%100)/10);cnt+=n%10; 18 t = n; 19 t = (int)fabs((double)t); 20 for (i = 0;; i++) 21 { 22 b = t%16; 23 if (b >= 10) 24 a[i] = c[b - 10]; 25 else 26 a[i] = b + ‘0‘; 27 t = (t - b) / 16; 28 if (t == 0) 29 break; 30 } 31 int cnt1=0; 32 for(int j=0;j<=i;j++) 33 { 34 if(a[j]>=‘A‘&&a[j]<=‘G‘) {a[j]-=‘7‘;} 35 if(a[j]>=‘0‘&&a[j]<=‘9‘) {a[j]-=‘0‘;} 36 cnt1+=a[j]; 37 } 38 t = n; 39 t = (int)fabs((double)t); 40 for (i = 0;; i++) 41 { 42 b = t%12; 43 if (b >= 10) 44 a[i] = c[b - 10]; 45 else 46 a[i] = b + ‘0‘; 47 t = (t - b) / 12; 48 if (t == 0) 49 break; 50 } 51 int cnt2=0; 52 for(int j=0;j<=i;j++) 53 { 54 if(a[j]>=‘A‘&&a[j]<=‘G‘) {a[j]-=‘7‘;} 55 if(a[j]>=‘0‘&&a[j]<=‘9‘) {a[j]-=‘0‘;} 56 cnt2+=a[j]; 57 } 58 if(cnt==cnt1&&cnt==cnt2) cout<<n <<" is a Sky Number."<<endl; 59 else cout<<n <<" is not a Sky Number."<<endl; 60 } 61 return 0; 62 }
标签:
原文地址:http://www.cnblogs.com/yifangfengjing/p/4252515.html