A1100 Mars Numbers (20 point(s))

数学问题

1. 原文

原题

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 Nlines 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:

1
2
3
4
5
4
29
5
elo nov
tam

Sample output:

1
2
3
4
hel mar
may
115
13

2. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
string ge[]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string shi[]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int main(){
int n;
cin>>n;
getchar();
while(n--){
string str;
getline(cin,str);
if (isdigit(str[0]))
{
int num = 0;
for (int i = 0; i < str.length(); ++i)
{
num = num*10+str[i]-'0';
}
if (num<13)
{
cout<<ge[num]<<endl;
}else if(num%13==0){
cout<<shi[num/13]<<endl;
}else{
cout<<shi[num/13]<<" "<<ge[num%13]<<endl;
}
}else{
if (str.find(" ")==string::npos)
{
int flag = 0;
for (int i = 0; i < 13; ++i)
{
if (str==ge[i])
{
flag = 1;
cout<<i<<endl;
break;
}
}
if (flag == 0)
{
for (int i = 0; i < 13; ++i)
{
if (str==shi[i])
{
cout<<i*13<<endl;
}
}
}
}else{
string s1,s2;
int i = 0;
for (; str[i] != ' '; ++i)
{
s1+=str[i];
}
i++;
for (; i < str.length(); ++i)
{
s2+=str[i];
}
int ans = 0;
for (int i = 0; i < 13; ++i)
{
if (s1==shi[i])
{
ans+=i*13;
break;
}
}
for (int i = 0; i < 13; ++i)
{
if (s2==ge[i])
{
ans+=i;
}
}
cout<<ans<<endl;

}
}
}


return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/03/A1100/
  • 发布时间: 2019-09-03 12:30
  • 更新时间: 2021-10-29 14:07
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!