PAT 乙级 1058. 选择题(20)

批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。

输入格式:

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

输出格式:

按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从1开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。

输入样例:

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) (2 b d) (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) (2 b c) (4 a b c d)

输出样例:

3
6
5
2 2 3 4

用个结构体存储每个题目的信息,然后提取出每个学生的选项,判定学生的选项是否和答案是相等的,否则就做相应的处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cstdio>

struct Item {
int score, unit, t;
char *choose = new char[6];
};

bool equal(const struct Item &a, const struct Item &b) {
if (a.t != b.t) return false;
for (int i = 0; i < a.t; i++) {
if (a.choose[i] != b.choose[i]) return false;
}
return true;
}

int main() {
int n = 0, m = 0;
scanf("%d %d", &n, &m);
struct Item *items = new struct Item[m];
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &items[i].score, &items[i].unit, &items[i].t);
for (int j = 0; j < items[i].t; j++) {
scanf(" %c", &items[i].choose[j]);
}
}

int *error = new int[m];
int maxValue = -1;
for (int i = 0; i < n; i++) {
int score = 0;
for (int j = 0; j < m; j++) {
struct Item s;
char c = getchar();
c = getchar();
scanf("%d", &s.t);
for (int k = 0; k < s.t; k++) {
c = getchar();
scanf("%c", &s.choose[k]);
}
c = getchar();
if (equal(items[j], s)) score += items[j].score;
else {
error[j]++;
if (error[j] > maxValue) maxValue = error[j];
}
}
printf("%d\n", score);
}

if (maxValue == -1) {
printf("Too simple");
} else {
printf("%d", maxValue);
for (int i = 0; i < m; i++) {
if (error[i] == maxValue) {
printf(" %d", i + 1);
}
}
}
delete[] items;
delete[] error;
return 0;
}