【PAT】【C++】1073 多选题常见计分法

mac2022-06-30  103

73. 多选题常见计分法

题目:批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 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 #include<iostream> #include<vector> using namespace std; struct ques { int score; //分数 int answer_qua; //可选答案个数 int correct_answer_num; //正确答案个数 int correct_answer[5] = {0};//正确答案 }; int main() { int n, m; //n个学生,m道题 scanf("%d %d", &n, &m); int wrong_re[100][5] = { 0 };//每道题的每个选项的错误次数 vector<ques> v; //输入m道题的数据 for (int i = 0; i < m; i++) { getchar(); ques temp_qu; scanf("%d %d %d", &temp_qu.score, &temp_qu.answer_qua, &temp_qu.correct_answer_num); /* cin >> temp_qu.score; cin >> temp_qu.answer_qua; cin >> temp_qu.correct_answer_num;*/ for (int j = 0; j < temp_qu.correct_answer_num; j++) { char in_put; scanf(" %c", &in_put); temp_qu.correct_answer[in_put-'a']=1; } v.push_back(temp_qu); } 测试输出 //for (int i = 0; i < v.size(); i++) //{ // for(int j=0;j<5;j++) // printf("%d", v[i].correct_answer[j]); // printf("\n"); //} //后续,学生输入答案,然后先后该道题的正确答案异或,结果不为0的话再进行与运算 for (int i = 0; i < n; i++) { double stu_score = 0.0; //记录学生的成绩 for (int j = 0; j < m; j++) //每个学生m道题 { getchar();//换行符 int num; //选择的答案个数 int an[5] = {0};//答案数组 scanf("(%d", &num); for (int x = 0; x < num; x++) { char a1; scanf(" %c", &a1); an[a1 - 'a'] = 1;//选择的字母对应数组的数设为1 } scanf(")"); //已得到第i个学生在第j道题的答案an[5] //测试输出学生的答案是否正确 /* for (int i1 = 0; i1 < 5; i1++) cout << an[i1]; cout << " ";*/ int cmp[5] = { 0 }; //记录学生该题的答案和正确答案的异或结果 int flag = 1;//记录这道题是否有错误选项 int flag1 = 1;//是错选还是漏选 1漏选 0错选 for (int i1 = 0; i1 < 5; i1++) { if (an[i1] != v[j].correct_answer[i1]) { cmp[i1] = 1; wrong_re[j][i1]++; flag = 0; if (v[j].correct_answer[i1] == 0)//错选 flag1 = 0; } } if (flag)//回答完全正确 { stu_score += v[j].score; } else { if (flag1) stu_score += double(v[j].score) / double(2); } } printf("%.1f\n", stu_score); } int max_cnt = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < 5; j++) { if (wrong_re[i][j] > max_cnt) { max_cnt = wrong_re[i][j]; } } } if (max_cnt == 0) { cout << "Too simple"; return 0; } for (int i = 0; i < m; i++) { for (int j = 0; j < 5; j++) { if (wrong_re[i][j] == max_cnt) { printf("%d %d-%c\n", max_cnt, i + 1, 'a' + j); } } } return 0; }
最新回复(0)