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 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
shui
代码
#include<bits/stdc++.h>
using namespace std;
string lg[13] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string hg[13] = {"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int main()
{
ios::sync_with_stdio(false);
int n ;
cin>>n;
string s;
getline(cin,s);
while(n --)
{
getline(cin,s);
if(s[0] >= '0' && s[0] <= '9') //表示数字转字符串
{
int sum = s.at(0) - '0';
for(int i = 1; i < s.length(); i++)
sum = sum * 10 + (s.at(i) - '0');
int kk = sum / 13;
int gg = sum % 13;
if(sum % 13 == 0 && sum > 0){
cout<<hg[kk]<<endl;
continue;
}
if(kk != 0)
cout<<hg[kk]<<" ";
cout<<lg[gg]<<endl;
}else
{
if(s.length() > 5)
{
string tt = "";
int cnt = 0;
for(int i = 0 ; i < s.length(); i++)
{
if(s.at(i) != ' ')
tt += s.at(i);
else
{
for(int j = 0 ; j < 13; j++){
if(hg[j] == tt)
cnt = 13 * j ;
}
tt.clear();
}
}
for(int i = 0; i < 13; i ++)
{
if(lg[i] == tt)
cnt += i;
}
cout<<cnt<<endl;
}else
{
for(int i = 0; i < 13; i ++)
{
if(s == lg[i])
{
cout<<i<<endl;
break;
}else if(s == hg[i])
{
cout<<i*13<<endl;
break;
}
}
}
}
}
return 0;
}