1073 多选题常见计分法 (20 分)

1073 多选题常见计分法 (20 分)

题意描述:

批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50% 分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。

输入格式:

输入在第一行给出两个正整数 N(≤1000)和 M(≤100),分别是学生人数和多选题的个数。随后 M 行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N 行,每行给出一个学生的答题情况,其每题答案格式为 (选中的选项个数 选项1 ……),按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。

输出格式:
按照输入的顺序给出每个学生的得分,每个分数占一行,输出小数点后 1 位。最后输出错得最多的题目选项的信息,格式为:错误次数 题目编号(题目按照输入的顺序从1开始编号)-选项号。如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺序输出。行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出 Too simple。

输入样例 1:

3 4 
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (3 b d e) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (1 c) (4 a b c d)

输出样例 1:

3.5
6.0
2.5
2 2-e
2 3-a
2 3-b

输入样例 2:

2 2 
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)

输出样例 2:

5.0
5.0
Too simple

解题思路:
Bob: 啊,又超时了,!!!∑(゚Д゚ノ)ノ
Alice: emm, 我觉得你是已经碰到了天花板了,你该再学点Python了,自己总结一下怎么才能把Python程序写的更快,更简洁,更优雅。
Bob: 你说的对,不过这可能要比较长的时间了,现在是处在瓶颈期了。
Alice: ヾ(◍°∇°◍)ノ゙加油。

代码:

from functools import cmp_to_key


def main():
    N, M = (int(x) for x in input().split())
    std_answer = []
    tot_scores = []
    for x in range(M):
        temp = [z for z in input().split()]
        tot_scores.extend([int(temp[0])])
        std_answer.extend([set(temp[3:])])
        
    wrongs = {}
    for index, _ in enumerate(std_answer):
        for x in std_answer[index]:
            wrongs["{}{}".format(index + 1, x)] = N


    for x in range(N):
        stu_answer = get_stu_answer(input())
        score = 0.0

        for index, _ in enumerate(stu_answer):
            if stu_answer[index] == std_answer[index]:
                score += tot_scores[index]
            elif stu_answer[index] < std_answer[index]:
                score += tot_scores[index] / 2.0

            for char in stu_answer[index]:
                temp_key = "{}{}".format(index + 1, char)
                if char not in std_answer[index]:
                    wrongs.setdefault(temp_key, 0)
                    wrongs[temp_key] += 1
                else:
                    wrongs[temp_key] -= 1
        print("{:.1f}".format(score))

    max_value = wrongs[max(wrongs, key=wrongs.get)]
    if max_value == 0:
        print("Too simple")
    else:
        ready = []
        for key in wrongs:
            if wrongs[key] == max_value:
                ready.extend([[int(key[0]), key[1]]])
        answers = sorted(ready, key=cmp_to_key(compare), reverse=False)
        for answer in answers:
            print("{} {}-{}".format(max_value,
                                    answer[0], answer[1]))


def compare(a, b):

    if a[0] != b[0]:
        return a[0] - b[0]
    else:
        if a[1] < b[1]:
            return -1
    return 1


def get_stu_answer(string):
    # 从string中提取出一位学生的答案,返回一个set的列表,每一个set存储一道题的答案。
    answer = []
    for x in string:
        if x == '(':
            flag = True
            temp = set()
            continue

        if flag:
            if is_alphabet(x):
                temp.add(x)

        if x == ')':
            answer.extend([temp])
            flag = False
            
    return answer


def is_alphabet(x):
    # 判断一个字符是不是英文小写字母
    return ord(x) >= ord('a') and ord(x) <= ord('z')

if __name__ == '__main__':
    main()

易错点:

  • 题目的编号可能是两位数,上面的代码应该是有bug的,(ᇂдᇂ )ノ┬─┬ノ┻━┻ ,(扶我起来,我还能改,(¦3」∠)
  • 用Python 容易超时啊 。

总结:

  • 待定
  • 待定
    1073 多选题常见计分法 (20 分)_第1张图片

你可能感兴趣的:(PAT游乐园)