批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 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
思路:
与1058相同的方法,只是这里要注意保存的信息要多一些,也是用数组索引保存
注意:
- 注意题目的错误题目的选项的意思是:
- 题目半对的情况下,没有被选择的正确答案
- 题目错误的情况下,正确答案以外的选项,以及未选的正确答案
代码:(C++) 有待优化
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
struct question
{
int score;
int option_num;
int true_num;
vector<char> answer;
};
struct answer
{
int num;
vector<char> ans;
};
vector<answer> getAnswer(string &str)
{
int first = str.find_first_of('(');
int last = str.find_first_of(')');
vector<answer> ans;
while(first != str.npos)
{
answer an;
an.num = str[first+1]-'0';
for(int i=first+1; i<last; i++)
{
if(str[i]>='a' && str[i]<='z')
an.ans.push_back(str[i]);
}
ans.push_back(an);
if(last == str.length()-1)
str = str.substr(last);
else
str = str.substr(last+1);
first = str.find_first_of('(');
last = str.find_first_of(')');
}
return ans;
}
int false_an[100][5] = {0};
int main()
{
int N,M;
vector<question> q;
double students[1000] = {0.0};
cin>>N>>M;
for(int i=0; i<M; i++) //录入题目信息
{
int a,b,c;
cin>>a>>b>>c;
question qs;
qs.score = a;
qs.option_num = b;
qs.true_num = c;
for(int i=0; i<c; i++)
{
char ch;
cin>>ch;
qs.answer.push_back(ch);
}
q.push_back(qs);
}
cin.ignore(10,'\n'); //清空上面的输入
for(int i=0; i<N; i++) //录入学生答题
{
string str_a;
getline(cin,str_a);
vector<answer> answers;
answers = getAnswer(str_a);
for(int j=0; j<answers.size(); j++)
{
// if(q[j].answer[j] != answers.ans[j])
answer res = answers[j];
bool flag = true;
for(int k=0; k<res.ans.size(); k++)
{
if(!binary_search(q[j].answer.begin(),q[j].answer.end(),res.ans[k])) //没找到答案
{
flag = false;
false_an[j][res.ans[k] - 'a']++;
}
}
// for(int z=0; z<res.ans.size(); z++)
// cout<<res.ans[z]<<' ';
// cout<<endl;
// cout<<q[j].true_num<<' '<<answers[j].num<<endl;
if(flag && q[j].true_num == answers[j].num) //满分
students[i] += q[j].score;
else if(flag && q[j].true_num != answers[j].num)
{
students[i] += q[j].score/2.0; //半对
for(int k=0; k<q[j].answer.size(); k++)
{
if(!binary_search(res.ans.begin(),res.ans.end(),q[j].answer[k])) //没找到这个选项
{
false_an[j][q[j].answer[k] - 'a']++;
}
}
}
else
{
for(int k=0; k<q[j].answer.size(); k++)
{
if(!binary_search(res.ans.begin(),res.ans.end(),q[j].answer[k])) //没找到这个选项
{
false_an[j][q[j].answer[k] - 'a']++;
}
}
}
}
}
for(int i=0; i<N; i++)
printf("%.1f\n",students[i]);
int max_n=-1;
for(int i=0; i<M; i++)
{
for(int j=0; j<5; j++)
{
if(false_an[i][j]>max_n)
max_n = false_an[i][j];
}
}
if(max_n == 0)
cout<<"Too simple";
else
{
for(int i=0; i<M; i++)
{
for(int j=0; j<5; j++)
{
if(false_an[i][j] == max_n)
cout<<max_n<<' '<<i+1<<'-'<<(char)(j+'a')<<endl;
}
}
}
return 0;
}