批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。
输入格式:
输入在第一行给出两个正整数 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
代码长度限制
16 KB
时间限制
300 ms
内存限制
64 MB
#include <iostream>
#include <cctype>
#include <string>
#include <cstring>
struct topic
{
int wrong_ct;
int max_score;
int option;
int good;
int good_option[5];
};
using namespace std;
int examine(topic*, char*);
int main()
{
const int MAX_SIZE{ 1000 };
int n, m;
cin >> n >> m;
int i = 0;
char ch;
topic* test = new topic[m];
for (i = 0; i < m; i++) //初始化以及录入
{
test[i].wrong_ct = 0;
memset(test[i].good_option, 0, sizeof(test[i].good_option));
cin >> test[i].max_score >> test[i].option >> test[i].good;
for (int j = 0; j < test[i].good; )
{
cin.get(ch);
if (isalpha(ch))
{
test[i].good_option[ch - 'a']++;
j++;
}
}
}
int j = 0;
int left = 1, right = 0;
int score = 0;
for (i = 0; i < n; i++)
{
left = 1;
score = 0;
char write[10000];
cin.getline(write, 10000);
while (write[0] == '\0')
cin.getline(write, 10000); //空行重新读
for (j = 0; j < m; j++) //每个学生答每道题的情况
{
while (write[left-1] != '(')
left++; //每道题输入括号内部第一个数字的位置
right = left + (write[left]-'0') * 2 + 1; //最后一个括号的位置
write[right] = '\0';
if (examine(&test[j], write + left)==1) //每次检验一道题
{
score += test[j].max_score;
}
else
{
//检验错误
test[j].wrong_ct++;
}
left = right+3;
}
cout << score << endl;
}
int max = 0;
for (i = 0; i < m; i++)
{
if (test[i].wrong_ct > max)
max = test[i].wrong_ct;
}
if (max != 0)
{
cout << max;
for (i = 0; i < m; i++)
{
if (test[i].wrong_ct == max)
{
cout.put(' ') << i + 1;
}
}
}
else
cout << "Too simple";
cout << endl;
delete[]test;
return 0;
}
int examine(topic* problem, char* left)
{
if ((*left - '0') != problem->good)
return 0;
char ch;
while (ch = *left)
{
if (isalpha(ch))
{
if ((problem->good_option[ch - 'a']) == 0)
return 0;
}
left++;
}
return 1;
}