题目描述
计分板
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 131072KB;其他语言 655360KB
题目描述:
假设你正在参加一场比赛,这场比赛有A,B,C…M一共13题。现在,你已经通过了n题,此时你注意到,大屏幕上有一个计分板,
里面记录了每一道题目前有多少人通过。你想知道,在剩下的还没有做出来题目当中,
哪一道题才是通过人数最多的题目?如果有多个这样的题目,取题号靠前的。
import sys
n = int(input().split()[0]) # 通过的题目数目n
abcd = [x for x in input()] # 已经通过的题目ABED...
numbers = [int(x) for x in input().split()]
all_abcd = list(range(65, 77+1)) # A,B,C...M 13道题的ASCALL码 想不起来用 ord('A') chr(65)
not_done_abcds = all_abcd.copy() # 没有通过的题目列表
for done_abcd in abcd:
not_done_abcds.remove(ord(done_abcd))
# 下面先找到通过人数最多的题目 用贪心策略
max_number = float('-inf')
max_index = float('inf')
for not_done in not_done_abcds:
if numbers[all_abcd.index(not_done)] > max_number or (numbers[all_abcd.index(not_done)] == max_number and all_abcd.index(not_done) < max_index):
max_index = all_abcd.index(not_done)
max_number = numbers[max_index]
sys.stdout.write(str(chr(all_abcd[max_index])))