3.15 PAT1044 乙级 python

火星数字

def huoxing(a):
	mars = {
	'tret':0,
	'jan':1,
	'feb':2,
	'mar':3,
	'apr':4,
	'may':5,
	'jun':6,
	'jly':7,
	'aug':8,
	'sep':9,
	'oct':10, 
	'nov':11, 
	'dec':12,
	'tam':13, 
	'hel':26, 
	'maa':39, 
	'huh':52, 
	'tou':65, 
	'kes':78, 
	'hei':91, 
	'elo':104, 
	'syy':117, 
	'lok':130, 
	'mer':143, 
	'jou':156
	}
	count = 0
	result = []
	if a[0].isalpha():
		for i in a:
			count += mars[i]
		return count
	else:
		k = int(a[0])
		left = k%13
		k = k//13*13
		if k != 0:
			result.append(list(mars.keys())[list(mars.values()).index(k)])
		if left != 0:
			result.append(list(mars.keys())[list(mars.values()).index(left)])
		if k==0 and left ==0:
			result.append('tret')
		return result
n = int(input())
a = []
for i in range(n):
	lst = huoxing(list(input().split()))
	a.append(lst)
for i in a:
	if isinstance(i,int):
		print(i)
	else:
		print(' '.join(i))

这个题的坑在于 到底输不输出tret 比如你输入65 到底是跳出来‘tou tret’还是‘tou’,不过经过试验是只需要输出‘tou’就可以了。

猜你喜欢

转载自blog.csdn.net/qq_39782006/article/details/88566136