People on Mars count their numbers with base 13:
For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (< 100). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.
Output Specification:
For each number, print in a line the corresponding number in the other language.
Sample Input:4 29 5 elo nov tamSample Output:
hel mar may 115 13
进制转换。
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<stack> 5 #include<set> 6 #include<map> 7 #include<queue> 8 #include<algorithm> 9 using namespace std; 10 string dight[2][13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec", 11 "tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"}; 12 int main(){ 13 //freopen("D:\\INPUT.txt","r",stdin); 14 int n,num; 15 string s; 16 scanf("%d",&n); 17 while(n--){ 18 cin>>s; 19 int i,j; 20 num=0; 21 if(s[0]>=‘0‘&&s[0]<=‘9‘){ 22 for(i=0;i<s.length();i++){ 23 num*=10; 24 num+=s[i]-‘0‘; 25 } 26 if(num>12){ 27 cout<<dight[1][num/13]; 28 num%=13; 29 if(num){ 30 cout<<" "<<dight[0][num]; 31 } 32 cout<<endl; 33 } 34 else{ 35 cout<<dight[0][num]<<endl; 36 } 37 } 38 else{ 39 for(i=0;i<13;i++){ 40 if(dight[1][i]==s){ 41 break; 42 } 43 } 44 if(i!=13){ 45 num+=13*i; 46 if(getchar()==‘ ‘){ 47 cin>>s; 48 for(i=0;i<13;i++){ 49 if(dight[0][i]==s){ 50 break; 51 } 52 } 53 num+=i; 54 } 55 } 56 else{ 57 for(i=0;i<13;i++){ 58 if(dight[0][i]==s){ 59 break; 60 } 61 } 62 num+=i; 63 } 64 printf("%d\n",num); 65 } 66 } 67 return 0; 68 }
原文:http://www.cnblogs.com/Deribs4/p/4842494.html