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
Process
如果你的第2、4测试点一直过不去,请试一下13转火星文是不是tam。
Code
#include<bits/stdc++.h>
using namespace std;
int n;
string gewei[] = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
string shiwei[] = { "","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
int main()
{
cin >> n;
string temp;
char a;
getchar();
for (int i = 0; i < n; i++) {
getline(cin, temp);
if (temp[0]<='9'&&temp[0]>='0')//数字
{
int tint = stoi(temp);
cout << (tint / 13 != 0 ? shiwei[tint / 13] : "") << ((tint / 13 != 0 && tint % 13 != 0) ? " " : "") << ((tint % 13 != 0 || tint == 0) ? gewei[tint % 13] : "") << endl;
}
else
{
int t1 = 0, t2 = 0;
string s1 = temp.substr(0, 3), s2 = "";
if (temp.size() > 4)
s2 = temp.substr(4, 3);
for (int j = 1; j < 13; j++) {
if (s1 == gewei[j] || s2 == gewei[j])
t2 = j;
if (s1 == shiwei[j])
t1 = j;
}
cout << t1 * 13 + t2 << endl;
}
}
return 0;
}