3.21 PAT1059 乙级 python(一个测试点超时)

C语言竞赛

import math
def prime(k):
	up = int(math.sqrt(k)+1)
	if k%2==0 and k!=2:
		return False
	elif k==2 or k==3:
		return True
	else:
		for i in range(3,up,2):
			if k%up==0:
				return False
		return True
def prize(a):
	if a == 1:
		return 'Mystery Award'
	elif prime(a):
		return 'Minion'
	else:
		return 'Chocolate'
n = int(input())
dic = {}
lst = []
for i in range(n):
	dic[input()] = prize(i+1)
m = int(input())
for i in range(m):
	x = input()
	if x not in dic.keys():
		print(x+': Are you kidding?')
	else:
		if x in lst:
			print(x+': Checked')
		else:
			print(x+': '+dic[x])
			lst.append(x)

 

你可能感兴趣的:(PAT,乙级,python)