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 Earth 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
tam
Sample Output:
hel mar
may
115
13
本题题意太误导人了。。主要就是tam输出了13,让我误以为hel是14,maa是15。完全理解错了。tam是13,hel是13*2=26,
maa是13*3=39.坑人。。13的倍数为特殊用例,即个位为0时省略不输出“tret” 其他的都正常 火星文个位的"tret"省略
14是tam jan 15是tam feb 16是tam mar 26是:hel 39是:maa
总之:数字到字符串-》个位是tret不输出
字符串到数字-》单个字串 个位串正常输出 十位串,其实是省略了个位的tret,也是两位串
多个字串:正常转13进制输出
#include<bits/stdc++.h>
using namespace std;
string I1[]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};//个位
string I2[]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};//十位
map<string,int> mp1,mp2;
void initMap(){
for(int i=0;i<=12;i++) mp1[I1[i]]=i;
for(int i=1;i<=12;i++) mp2[I2[i]]=i;
}
void int2str(string s){
int n;
sscanf(s.c_str(),"%d",&n);
if(n<13) cout<<I1[n];
else{
cout<<I2[n/13];
if(n%13!=0) cout<<" "<<I1[n%13];//个位tret不输出
}
cout<<endl;
}
void str2int(string s){
int n=s.find(" ");
if(n==-1){//一个串
if(mp1.count(s)!=0) cout<<mp1[s];
else cout<<mp2[s]*13;//省略了0"tret"的大于12的数
}else{//2串
cout<<(mp2[s.substr(0,n)])*13+mp1[s.substr(n+1)];
}
cout<<endl;
}
int main(){
// freopen("in.txt", "r", stdin);
initMap();
int n;
string s;
cin>>n;
cin.get();//过滤换行
while(n--){
getline(cin,s);
if(isdigit(s[0])){//13进制int型
int2str(s);
} else{//字符型
str2int(s);
}
}
return 0;
}