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
tam
Sample Output:
hel mar
may
115
13
注意点:①如果输入数字为13的倍数,即需输出十位的字符串,要考虑空格
Tips:
如果想用printf输出string格式的字符串,scanf输入string类型,可以用如下语句
printf("%s",s.c_str());
string s;
s.resize(10);
scanf("%s",s);
关于substr()的用法:
string temp = s.substr(i)
//从s的第i个字符开始一直取到最后
string temp = s.substr(i,len)
//从s的第i个字符开始取len长
#include <iostream>
#include <string>
using namespace std;
const string ge[14]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
const string shi[14]={"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int main(){
int n;
scanf("%d\n", &n);
for(int i = 0; i < n; ++ i){
string s;
getline(cin, s);
if(isdigit(s[0])){
int temp = stoi(s);
if(temp >= 13)
printf("%s", shi[temp / 13].c_str());
if(temp > 13 && temp % 13 != 0)
printf(" ");
if(temp % 13 != 0 || temp == 0)
printf("%s", ge[temp % 13].c_str());
}
else{
int ans = 0;
string x = s.substr(0, 3);
for(int i = 0; i < 13; ++ i)
if(shi[i] == x)
ans += (i * 13);
x = s.substr(s.length() - 3);
for(int i = 0; i < 13; ++ i)
if(ge[i] == x)
ans += i;
printf("%d", ans);
}
printf("\n");
}
}