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
重点就是别打错字呜呜 因为这个错了好几次
#include<bits/stdc++.h>
using namespace std;
map <string, int>a;
map <int, string>hb;
map <int, string>lb;
void init(){
a["tret"] = 0;
a["jan"] = 1;
a["feb"] = 2;
a["mar"] = 3;
a["apr"] = 4;
a["may"] = 5;
a["jun"] = 6;
a["jly"] = 7;
a["aug"] = 8;
a["sep"] = 9;
a["oct"] = 10;
a["nov"] = 11;
a["dec"] = 12;
a["tam"] = 1 * 13;
a["hel"] = 2 * 13;
a["maa"] = 3 * 13;
a["huh"] = 4 * 13;
a["tou"] = 5 * 13;
a["kes"] = 6 * 13;
a["hei"] = 7 * 13;
a["elo"] = 8 * 13;
a["syy"] = 9 * 13;
a["lok"] = 10 * 13;
a["mer"] = 11 * 13;
a["jou"] = 12 * 13;
lb[0] = "tret";
lb[1] = "jan";
lb[2] = "feb";
lb[3] = "mar";
lb[4] = "apr";
lb[5] = "may";
lb[6] = "jun";
lb[7] = "jly";
lb[8] = "aug";
lb[9] = "sep";
lb[10] = "oct";
lb[11] = "nov";
lb[12] = "dec";
hb[1] = "tam";
hb[2] = "hel";
hb[3] = "maa";
hb[4] = "huh";
hb[5] = "tou";
hb[6] = "kes";
hb[7] = "hei";
hb[8] = "elo";
hb[9] = "syy";
hb[10] = "lok";
hb[11] = "mer";
hb[12] = "jou";
}
void solve(string s){
string s1, s2;
s1 = s.substr(0, 3);
int len = s.length();
if(len > 4){
s2 = s.substr(4, len - 4);
cout << a[s1] + a[s2] << endl;
}
else cout << a[s1] << endl;
}
void solve1(int x){
int x_, y_;
if(x > 12){
y_ = x / 13;
x_ = x % 13;
if(x_ != 0) cout << hb[y_] << " " << lb[x_] << endl;
else cout << hb[y_] << endl;
}
else {
x_ = x;
cout << lb[x_] << endl;
}
}
int main()
{
init();
int T;
cin >>T;
getchar();
string s;
int x, len;
while(T--){
getline(cin, s);
x = 0;
len = s.length();
if(s[0] >= '0' && s[0] <= '9') {
for(int i = 0; i < len; i++){
x = x * 10 + (s[i] - '0');
}
solve1(x);
}
else solve(s);
}
return 0;
}