1058. 选择题(20)

来源:互联网 发布:c语言声明 编辑:程序博客网 时间:2024/05/29 07:49

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

输入格式:

输入在第一行给出两个正整数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

分析
处理数据结构比较烦,我也不会STL,自己整一堆结构体,代码写的很长,就当培养耐心吧。

#include <iostream>using namespace std;struct Answer{//存储正确答案和分数的结构     int score;//总分数     int totalOptions;//选项数     int rightAnswer;//正确选项数     char *Option;//正确答案 };Answer createAnswer(int score,int totalOptions,int rightAnswer,char *options){//初始化答案     Answer ans;    ans.Option=new char[rightAnswer];    ans.score=score;    ans.totalOptions=totalOptions;    ans.rightAnswer=rightAnswer;    for(int i=0;i<ans.rightAnswer;i++){        ans.Option[i]=options[i];    }    return ans;} struct AnswerOne{    int Num;//题目选项     char *Answer;};AnswerOne initAO(int Num,char *Answer){//初始化 AnswerOne    AnswerOne ao;    ao.Num=Num;    ao.Answer=new char[Num];    for(int i=0;i<Num;i++){        ao.Answer[i]=Answer[i];    }    return ao;} struct PeoplesAnswer{    int questions;//题目数    AnswerOne *answers; }; PeoplesAnswer initPA(int questions,AnswerOne *answers){//初始化 PeoplesAnswer    PeoplesAnswer pa;    pa.questions=questions;    pa.answers=new AnswerOne[questions];    for(int i=0;i<questions;i++){        pa.answers[i]=answers[i];    }    return pa;}int Check(Answer &ans,AnswerOne &ao){    if(ans.rightAnswer!=ao.Num)return 0;    else{        for(int i=0;i<ao.Num;i++){            int flag=0;            for(int j=0;j<ans.rightAnswer;j++){                if(ao.Answer[j]==ans.Option[i])flag++;            }            if(!flag)return 0;        }    }    return ans.score;}int checkScore(Answer *ans,PeoplesAnswer *pa,int *WrongRes){    int score=0;    for(int i=0;i<pa->questions;i++){        if(Check(ans[i],pa->answers[i])==0)WrongRes[i]++;        score+=Check(ans[i],pa->answers[i]);    }    return score;}int main(){    int people,questions;//人数,题数     cin>>people>>questions;    Answer answers[questions];    for(int i=0;i<questions;i++){        int score,totalOptions,rightAnswer;        cin>>score>>totalOptions>>rightAnswer;        char options[rightAnswer];        getchar();         for(int j=0;j<rightAnswer;j++){            //cin>>options[i];            scanf("%c",&options[j]);//这样写正确             getchar();         }        answers[i]=createAnswer(score,totalOptions,rightAnswer,options);    }    PeoplesAnswer PAs[people];    for(int i=0;i<people;i++){//每个人         AnswerOne AOs[questions];        scanf("\n");        for(int j=0;j<questions;j++){//每个问题             int Num;            char *Answer;            if(j!=0)scanf(" ");            scanf("(%d ",&Num);            Answer=new char[Num];            for(int k=0;k<Num;k++){//每个选项                 scanf(" %c",&Answer[k]);            }            scanf(")");            AOs[j]=initAO(Num,Answer);        }        PAs[i]=initPA(questions,AOs);    }    int WrongQues[questions];    for(int i=0;i<questions;i++){        WrongQues[i]=0;    }    for(int i=0;i<people;i++){        printf("%d",checkScore(answers,&PAs[i],WrongQues));             printf("\n");    }    int Max=WrongQues[0];    for(int i=0;i<questions;i++){        if(Max<WrongQues[i])Max=WrongQues[i];    }    if(Max!=0)printf("%d",Max);    for(int i=0;i<questions;i++){        if(Max==WrongQues[i]&&Max!=0)printf(" %d",i+1);    }    if(Max==0)printf("Too simple");    return 0; }