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 tamSample Output:
hel mar may 115 13
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <cstdlib>
using namespace std;
map<string,int>map1,map2;
void init_map1(){
map1.insert(make_pair("tret",0));
map1.insert(make_pair("jan",1));
map1.insert(make_pair("feb",2));
map1.insert(make_pair("mar",3));
map1.insert(make_pair("apr",4));
map1.insert(make_pair("may",5));
map1.insert(make_pair("jun",6));
map1.insert(make_pair("jly",7));
map1.insert(make_pair("aug",8));
map1.insert(make_pair("sep",9));
map1.insert(make_pair("oct",10));
map1.insert(make_pair("nov",11));
map1.insert(make_pair("dec",12));
}
void init_map2(){
map2.insert(make_pair("tret",0));
map2.insert(make_pair("tam",1));
map2.insert(make_pair("hel",2));
map2.insert(make_pair("maa",3));
map2.insert(make_pair("huh",4));
map2.insert(make_pair("tou",5));
map2.insert(make_pair("kes",6));
map2.insert(make_pair("hei",7));
map2.insert(make_pair("elo",8));
map2.insert(make_pair("syy",9));
map2.insert(make_pair("lok",10));
map2.insert(make_pair("mer",11));
map2.insert(make_pair("jou",12));
}
char str1[][8]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char str2[][8]={"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
void convert_to_mar(char *str){
int num = atoi(str);
int high = num/13;
int low = num%13;
if(!high)
cout <<str1[low] <<endl;
else{
cout <<str2[high];
if(low)
cout << ' ' <<str1[low];
cout <<endl;
}
}
void convert_to_earth(char *str){
int size = strlen(str);
if(size < 4){
string strr = str;
int high = map2[strr];
high = 13*high;
if(!high)
high = map1[strr];
cout <<high <<endl;
}else{
char *p2 = str+4;
str[3] = '\0';
string strr1 = str;
string strr2 = p2;
int high = map2[strr1];
int low = map1[strr2];
int res = high*13+low;
cout <<res <<endl;
}
}
int main()
{
int N;
char str[16];
init_map1();
init_map2();
cin >>N;
getchar();
while(N){
gets(str);
if(str[0] <='9' &&str[0] >= '0')
convert_to_mar(str);
else
convert_to_earth(str);
N--;
}
return 0;
}