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
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = ; int n;
string s;
char s1[MAX][] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char s2[MAX][] = {" ", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; int my_pow(int x, int n)
{
int ans = ;
while (n)
{
if (n & ) ans *= x;
x *= x;
n >>= ;
}
return ans;
} int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%d", &n);
getchar();
for (int i = ; i <= n; ++ i)
{
getline(cin, s);
if (isalpha(s[]))
{
int len = s.size();
if (len >= )
{
char str1[], str2[];
int a = , b = , ans = ;
for (a, b; a < len; ++ a, ++ b)
{
if (s[a] == ' ') break;
str1[b] = s[a];
}
str1[b] = '\0';
++ a, b = ;
for (a, b; a < len; ++ a, ++ b)
str2[b] = s[a];
str2[b] = '\0';
for (int i = ; i < ; ++ i)
{
if (strcmp(s1[i], str2) == )
{
ans += i;
break;
}
}
for (int i = ; i <= ; ++ i)
{
if (strcmp(s2[i], str1) == )
{
ans += i * ;
break;
}
}
printf("%d\n", ans);
}
else
{
char str1[];
for (int i = ; i < len; ++ i)
str1[i] = s[i];
str1[len] = '\0';
bool flag = false;
for (int i = ; i < ; ++ i)
{
if (strcmp(str1, s1[i]) == )
{
flag = true;
printf("%d\n", i);
break;
}
}
if (flag) continue;
for (int i = ; i < ; ++ i)
{
if (strcmp(str1, s2[i]) == )
{
printf("%d\n", i * );
break;
}
}
}
}
else
{
int ans = , len = s.size(), t1, t2;
for (int i = , j = len - ; i < len; ++ i, -- j)
ans += (s[i] - '') * my_pow(, j);
t1 = ans / , t2 = ans % ;
if (ans <= )
printf("%s\n", s1[ans]);
else if (t2 == )
printf("%s\n", s2[t1]);
else
printf("%s %s\n", s2[t1], s1[t2]);
}
}
return ;
}