PAT_B_1058 选择题 (20 分)

批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。

输入格式:

输入在第一行给出两个正整数 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 <iostream>
#include <string.h>
using namespace std;
struct multioption
{
    int score;
    int optcount;
    int roptcount;
    bool right[5]={false,false,false,false,false};
};
int main()
{
    int N,M;//N--学生人数、 M--多选题个数
    cin>>N>>M;
    multioption mopt[M];
    for(int i=0;i<M;i++)
    {
        multioption mo;
        cin>>mo.score;
        cin>>mo.optcount;
        cin>>mo.roptcount;
        for(int j=0;j<mo.roptcount;j++)
        {
            char tempch;
            cin>>tempch;
            mo.right[tempch-'a']=true;
        }
        mopt[i]=mo;
    }
    int stuScore[N];
    char stuAns[2000];
    int wrongcount[M];        //每题出错次数
    int maxwrong=0;            //出错最多数
    memset(wrongcount,0,sizeof(wrongcount));
    memset(stuScore,0,sizeof(stuScore));
    cin.ignore();            //忽略之前所读取的回车符
    int tooSimple=1;
    for(int i=0;i<N;i++)
    {
        cin.getline(stuAns,2000);
        int stucount=0;
        int len=strlen(stuAns);
        int flag=0,optflag=1,opcou;
        for(int j=0;j<len;j++)
        {
            if(stuAns[j]=='(')
            {
                flag=1;
                optflag=1;            //重置此题正确与否的标志为
                opcou=stuAns[++j]-'0';  //读取括号后的第一个数字,即为所选选项个数
                continue;
            }
            if(stuAns[j]==')')
            {
                flag=0;
                if(optflag) stuScore[i]+=mopt[stucount].score;    //此题正确
                else                                //此题错误
                {
                    tooSimple=0;
                    wrongcount[stucount]++;
                    if(maxwrong<wrongcount[stucount]) maxwrong=wrongcount[stucount];
                }
                stucount++;
                continue;
            }
            if(flag)            //遍历到括号内
            {
                if(mopt[stucount].roptcount==opcou)        //所选个数与正确个数相同
                {
                    int ttt=stuAns[j]-'a';
                    if(ttt>=0&&ttt<=5)
                    {
                        if(!mopt[stucount].right[ttt])    //答案错误,修个标志位
                            optflag=0;
                    }
                }
                else
                    optflag=0;

            }
        }
    }
    for(int i=0;i<N;i++)
        cout<<stuScore[i]<<endl;
    if(tooSimple) cout<<"Too simple";            //测试点1,如果没有错,就输出tooSimple
    else
    {
        cout<<maxwrong;
        for(int i=0;i<M;i++)
        {
            if(maxwrong==wrongcount[i])
            {
                cout<<" "<<i+1;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/id33749110/article/details/86562922