題目鏈接:https://pintia.cn/problem-sets/994805260223102976/problems/994805270356541440
題目描述
批改多選題是比較麻煩的事情,本題就請你寫個程序幫助老師批改多選題,並且指出哪道題錯的人最多。
輸入
輸入在第一行給出兩個正整數 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
代碼
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
int main() {
int n, m, temp, k;
scanf("%d%d", &n, &m);
vector<set<char>> right(m); //向量有m個元素
vector<int> total(m), wrongCnt(m);
for(int i = 0; i < m; i++) {
scanf("%d%d%d", &total[i], &temp, &k);
for(int j = 0; j < k; j++) {
char c;
scanf(" %c", &c);
right[i].insert(c); //插入到末尾
}
}
for(int i = 0; i < n; i++) {
int score = 0;
scanf("\n"); //也可用getchar()
for(int j = 0; j < m; j++) {
if(j != 0) scanf(" "); //別忘了吸收空格
scanf("(%d", &k);
set<char> st;
char c;
for(int l = 0; l < k; l++) {
scanf(" %c", &c);
st.insert(c);
}
scanf(")");
if(st == right[j]) {
score += total[j];
} else {
wrongCnt[j]++;
}
}
printf("%d\n", score);
}
int maxWrongCnt = 0;
for(int i = 0; i < m; i++) {
if(wrongCnt[i] > maxWrongCnt) {
maxWrongCnt = wrongCnt[i];
}
}
if(maxWrongCnt == 0)
printf("Too simple");
else {
printf("%d", maxWrongCnt);
for(int i = 0; i < m; i++) {
if(wrongCnt[i] == maxWrongCnt) {
printf(" %d", i + 1);
}
}
}
return 0;
}