PAT乙级-1073 多选题常见计分法 (20分)

点击链接PAT乙级-AC全解汇总

题目:
批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 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<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件

int main()
{
    int N, M;
    cin >> N >> M;

    //0:score 1-5:abcde 6:num_true
    int score_key[M][8];
    memset(score_key, 0, sizeof(score_key));

    //遍历答案
    for (int i = 0; i < M; i++)
    {
        cin >> score_key[i][0];
        int options, num_true;
        cin >> options >> num_true;
        score_key[i][6] = num_true;
        for (int j = 0; j < num_true; j++)
        {
            char t;
            cin >> t;
            score_key[i][t - 'a' + 1] = 1;
        }
    }
    getchar();

    //选项错误次数
    int wrong_times[M][6] = { 0 };
    //遍历学生
    for (int i = 0; i < N; i++)//第i个学生
    {
        double score_stu=0; //学生得分
        string student; //学生答案
        getline(cin, student);
        for (int j = 0; j < M; j++)//第j道题
        {
            student.erase(0, student.find('(') + 1);

            //记录这道题学生的答案
            int stu_answer[6]={0};
            for (int k = 0; k < student[0] - '0'; k++)
            {
                student.erase(0, student.find(' ') + 1);
                stu_answer[student[0]-'a'+1]=1;
            }

            //对比正确答案并记录错误选项
            int flag_score=10;//少选了就-1,多选了就=0
            for(int k=1;k<=5;k++)
            {
                //abcde五个选项
                if(score_key[j][k]&&!stu_answer[k])//少选
                {
                    flag_score--;
                    wrong_times[j][k]++;
                }
                else if(!score_key[j][k]&&stu_answer[k])//多选
                {
                    flag_score=0;
                    wrong_times[j][k]++;
                }
            }

            //计算这道题得分
            if(flag_score==10) score_stu+=score_key[j][0];
            else if(flag_score>0) score_stu+=1.0*score_key[j][0]/2;

        }
        printf("%.1f\n",score_stu);
    }

    //遍历错误答案,找错误次数最多的答案
    int max_times=0;
    for (int i = 0; i < M; i++)
    {
        for (int j = 1; j <= 5; j++)
        {
            if(max_times<wrong_times[i][j])
               max_times=wrong_times[i][j];
        }
    }

    //输出错误次数最多的答案
    if(max_times==0)
        cout<<"Too simple"<<endl;
    else
    {
        for (int i = 0; i < M; i++)
        {
            for (int j = 1; j <= 5; j++)
            {
                if(max_times==wrong_times[i][j])
                   printf("%d %d-%c\n",max_times,i+1,'a'+j-1);
            }
        }
    }

    return 0;
}

这道题有点烦,但不算很难,各变量名称注释写的很详细了~

发布了82 篇原创文章 · 获赞 1 · 访问量 1662

猜你喜欢

转载自blog.csdn.net/qq_34451909/article/details/104939134