1100. Mars Numbers (20)
People on Mars count their numbers with base 13:
- Zero on Earth is called "tret" on Mars.
- The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively.
- For the next higher digit, Mars people name the 12 numbers as "tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou", respectively.
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
#include<iostream> #include<vector> #include<stdio.h> #include<algorithm> #include<map> using namespace std; int main() { int n; string Mars1[13]= {"tret","jan","feb","mar","apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; string Mars2[13]= {"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer","jou"}; map<string,int> nums1; map<string,int> nums2; for(int i=0; i<13; i++) { nums1[Mars1[i]]=i; nums2[Mars2[i]]=i; } scanf("%d%*c",&n); char str1[5],str2[5],ch; for(int i=0; i<n; i++) { scanf("%s%c",str1,&ch); if('0'<=str1[0]&&str1[0]<='9')//数字 { int a,b,number; sscanf(str1,"%d",&number); a= number%13; b= number/13; if(b==0&&a==0) printf("tret\n"); else if(b==0&&a!=0) printf("%s\n",Mars1[a].c_str()); else if(b!=0&&a==0) printf("%s\n",Mars2[b].c_str()); else printf("%s %s\n",Mars2[b].c_str(),Mars1[a].c_str()); } else//Mars { int a=0,b=0,number; if(ch==' ')//输入俩个数时 { scanf("%s%c",str2,&ch); a=nums2[str1]; b=nums1[str2]; if(!b) b=nums2[str2];//高位为0或者没找到时从低位找 number = a *13 +b; } else//输入一个 { a = nums2[str1];//从高位找 if(a)//如果找到 number = a*13; else//没找到为低位 number = nums1[str1]; } printf("%d\n",number); } } return 0; }