1044 火星数字 (20分)
火星人是以 13 进制计数的:
- 地球人的 0 被火星人称为 tret。
- 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
- 火星人将进位以后的 12 个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。
例如地球人的数字 29
翻译成火星文就是 hel mar
;而火星文 elo nov
对应地球数字 115
。为了方便交流,请你编写程序实现地球和火星数字之间的互译。
输入格式:
输入第一行给出一个正整数 N(<100),随后 N 行,每行给出一个 [0, 169) 区间内的数字 —— 或者是地球文,或者是火星文。
输出格式:
对应输入的每一行,在一行中输出翻译后的另一种语言的数字。
输入样例:
4
29
5
elo nov
tam
输出样例:
hel mar
may
115
13
这个题思路不难,就是输出的格式很繁琐。
1.地球数——>火星数
(1)只有火星数的个位数——只输出个位数
(2)只有火星数的十位数——只输出十位数(不必再去输出个位的零)
(3)二者都有——输出的个位数和十位数之间有空格
2.火星数——>地球数
(1)中间没有空格分割——火星数的个位数
(2)中间没有空格分割——火星数的十位数
(3)中间有空格分割——13进制转十进制
Python代码:
#x:火星文字1-12
#Martian text 1-12
x = ['tret','jan','feb','mar','apr','may','jun','jly','aug','sep','oct','nov','dec']
#y:进位后的火星文字1-12
#Martian text after rounding 1-12
y = ['','tam','hel','maa','huh','tou','kes','hei','elo','syy','lok','mer','jou']
for i in range(int(input())):
a=input()
#数字(地球)
#digital(Earth)
if a.isdigit():
b=int(a)//13
c=int(a)%13
#未进位
#No carry
if b==0:
print(x[c])
#进位但个位无数字
#Carry but no single digit
elif c==0:
print(y[b])
#进位且个位有数字
#Carry and the ones digit has a number
else:
print(y[b]+' '+x[c])
else:
#字符串(火星文)
#String(Martian text)
#两位都存在
#Both digits exists
if len(a.split(' '))==2:
b,c=a.split(' ')
if (b) in y:
b=y.index(b)
if c in x:
c=x.index(c)
else:
c=a
#只存在个位
#Only the ones place
if c in x:
c=x.index(c)
b=0
#只存在进位,个位无数字
#Carry only,
else:
b=y.index(c)
c=0
print(b*13+c)