1059. C语言竞赛(20)——Python

测试点1与2运行超时

#判断素数
import math
def isPrime(n):
	if n <= 1:
		return False
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

#得到获奖名单	
num_guys = input()	
num_guys = int(num_guys)
guys_list = []
guys_dir = {}
for i in range(num_guys):
	guy_id = input()
	guys_dir[guy_id] = 0
	guys_list.append(guy_id)
	guys_dir[guy_id] = i + 1

#判断输入的id获奖情况	
judge_guys = input()
judge_guys = int(judge_guys)
for i in range(judge_guys):
	id = input()
	if id in guys_list and guys_dir[id] > 0:
		rank = guys_dir[id]
		if rank == 1:			
			print(id + ': ' + 'Mystery Award')
		elif isPrime(rank):
		
			print(id + ': ' + 'Minion')
		else:
			print(id + ': ' + 'Chocolate')
		guys_dir[id] = 0
	elif id not in guys_list:
		print(id + ': ' + 'Are you kidding?')
	else:
		print(id + ': ' + 'Checked')
	


你可能感兴趣的:(python练习(未完成),python)