PAT B -1073 common multiple choice scoring method (20 minutes)

Click on the link full solution summary PAT B -AC

Title:
marking multiple choice is more troublesome thing, there are many different scoring system. One of the most common scoring is: if the candidates selected partially correct option and do not select any errors option, you get a 50% score; if any one of the candidates chose the wrong option, you can not score. This question will ask you to write a program to help teachers mark multiple choice questions, and point out which option which most questions of the wrong people.

Input format:
Input give two positive integers N (≤1000) and M (≤100) in the first row, the number of students and are the number of multiple-choice questions. Subsequently M rows, each row is sequentially given value out of a question (a positive integer of not more than 5), the number of options (a positive integer not less than 2 and not more than 5), the correct number of options (option not exceed a positive integer), all the correct options. Note that the options for each question from lowercase letters begin a sequential arrangement. Among all separated by a space. The last N lines, each student is given a case to answer, each question answer format (选中的选项个数 选项1 ……), the title given in the order. Note: Title ensure students answer the case is legitimate, the number of options that is selected does not exist than the actual number of options.

Output format:
given a score of each student in the order of input, one bit after each score line, the output of the decimal point. Final output wrong most of the options subject information, in the format: 错误次数 题目编号(题目按照输入的顺序从1开始编号)-选项号. If there side by side, each row is an option, according to the title output in ascending numerical order; then press Option-parallel output number in ascending order. Line from beginning to end may not have the extra space. If all the topics no one wrong, the output in the last line Too simple.

Sample Input 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)

Output Sample 1:

3.5
6.0
2.5
2 2-e
2 3-a
2 3-b

Sample Input 2:

2 2 
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)

Output Sample 2:

5.0
5.0
Too simple

My code:

#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;
}

This question is a little annoying, but not too difficult, each variable name Notes written in great detail ~

Published 82 original articles · won praise 1 · views 1662

Guess you like

Origin blog.csdn.net/qq_34451909/article/details/104939134