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
stoi(a)函数可以将字符串直接转化为int型
#include "pch.h"
#include <iostream>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<math.h>
using namespace std;
string low[13] = { "tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec" };
string high[13] = { "tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou" };
void fun1(int t)
{
if (t / 13)
cout << high[t / 13];
if (t / 13 && t % 13)
cout << " ";
if (t % 13 || t == 0)
cout << low[t%13];
cout << endl;
}
void fun2(string s)
{
string s1 = s.substr(0, 3), s2;
int t1=0, t2=0;
if (s.length() > 3)
s2 = s.substr(4, 3);
for (int i = 0; i < 13; i++)
{
if (low[i] == s1 || low[i] == s2)
t2 = i;
if (high[i] == s1)
t1 = i;
}
cout << t1 * 13 + t2 << endl;
}
int main()
{
int n;
cin >> n;
string a;
getchar();
for (int p = 0; p < n; p++)
{
getline(cin, a);
if (isdigit(a[0]))
fun1(stoi(a));
else
fun2(a);
}
}