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
#include<iostream>
#include<vector>
#include<unordered_map>
#include<cstring>
using namespace std;
int main(){
string junior[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string senior[13] = {"-", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
unordered_map<string, int> j_mars_earth;
unordered_map<string, int> s_mars_earth;
for(int i = 0; i < 13; i++){
j_mars_earth[junior[i]] = i;
s_mars_earth[senior[i]] = i;
}
int n;
cin >> n;
getchar();
for(int i = 0; i < n; i++){
string temp;
getline(cin, temp);
if(temp[0] >= '0' && temp[0] <= '9'){ //earth_mars
int num;
num = stoi(temp);
int s = num / 13;
int j = num % 13;
if(num <= 12){
printf("%s\n", junior[num].c_str());
}else if (j == 0)
{
printf("%s\n", senior[s].c_str());
}else
{
printf("%s %s\n", senior[s].c_str(), junior[j].c_str());
}
}else //mars_earth
{
if(temp.length() > 4){
string a, b;
a = temp.substr(0, 3);
b = temp.substr(4, 3);
printf("%d\n", s_mars_earth[a] * 13 + j_mars_earth[b]);
}else
{
if(temp == "tret"){
printf("0\n");
}else
{
if(j_mars_earth[temp] != 0){
printf("%d\n", j_mars_earth[temp]);
}else if(s_mars_earth[temp] != 0)
{
printf("%d\n", s_mars_earth[temp] * 13);
}
}
}
}
}
return 0;
}
本文介绍了一种特殊的计数系统,即火星上的13进制计数法,并提供了一个程序,用于在地球的十进制计数系统和火星的13进制计数系统之间进行相互转换。该程序能够处理输入的火星计数或地球计数,将其转换为对应的另一种计数形式。

被折叠的 条评论
为什么被折叠?



