pat乙级 1073 多选题常见计分法 与1058 选择题
两道题很相似并且都没有什么难度,唯一的问题就是要处理的数据比较多,用python解要处理好列表的包含关系
首先1058
N, M=map(int,input().split())
nums = []
ans = []
score = []
for i in range(M):
ls = list(input().split())
scores = int(ls[0])
right = int(ls[2])
choice = ls[3:]#读入分数和正确答案
ans.append([scores, right, choice])#记录每个分数和正确答案
error = [0 for i in range(M)]#用于记录每道题错误的次数
score = [0 for i in range(N)] #用于记录每位学生的分数
for i in range(N):
ls = input()
ls = ls.replace('(', '')
ls = ls.split(')')#处理括号
for j in range(M):
l = ls[j].strip().split()
num = int(l[0])
choice = ans[j]
anss = l[1:]
if anss == choice[2]:#每道题都判断,如果对了就加分,错了就记录错误次数加一
score[i] += choice[0]
else:
error[j] += 1
for a in score:#输出分数
print(a)
max = max(error)
if max == 0 :
print("Too simple")
else :#输出错误最多的题目
result = []
for index, errorlist in enumerate(error, 1):
if errorlist == max:
result.append(str(index))
result = [str(max)] + result
print(' '.join(result))
然后1073,这个比上一题要复杂一些,但是整体思路和上一题一样,在上一题基础上加一个记录每个选项错误的次数
N, M=map(int,input().split())
nums = []
ans = []
score = []
for i in range(M):
ls = list(input().split())
scores = int(ls[0])
right = int(ls[2])
choice = ls[3:]
wrong = {}
for j in ['a', 'b', 'c', 'd', 'e']:#每一道题目都记录每个选项错误的次数,对的没选和错的选了都算错
wrong[j] = 0
ans.append([scores, right, choice, wrong])
error = [0 for i in range(M)]
score = [0 for i in range(N)]
for i in range(N):
ls = input()
ls = ls.replace('(', '')
ls = ls.split(')')
for j in range(M):
l = ls[j].strip().split()
num = int(l[0])
choice = ans[j]
anss = l[1:]
if set(anss) <= set(choice[2]):
if anss == choice[2]:
score[i] += choice[0]
else :
score[i] += choice[0] / 2#注意这个不算总的错误次数
for m in choice[2]:#对了没选
if m not in anss:
ans[j][3][m] +=1
else:
for m in choice[2]:#对了没选
if m not in anss:
ans[j][3][m] +=1
for n in anss:#错的选了
if n not in choice[2]:
ans[j][3][n] +=1
error[j] += 1
for a in score:
print("{:.1f}".format(a))
max = max(error)#这里的error只是题目的错误次数,如果为零就输出Too Simple
if max == 0 :
print("Too simple")
else :#如果不为零就不要按照这个记为最大值,需要在每个选项中重新寻找最大值,
#因为如果还是计算每道题目最大值的话,可能一道题目的选项错误比较分散,而这1073只需要输出单个选项错误
#类似一道题目错了三次,但是是abc选项各一次,在最后输出的时候找不到等于三的错误选项导致没有输出,所以这里要再找一次错误次数最多的选项
max = 0
for m in ans:
for n in m[3]:
if m[3][n] > max :
max = m[3][n]
a = 0
for m in ans:
a += 1
for n in m[3]:
if m[3][n] == max :
print("{} {}-{}".format(max, a, n))