码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 1058 选择题

时间:2018-12-08 17:02:57      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:its   clu   多选   比较   int   string   题目   个学生   core   

https://pintia.cn/problem-sets/994805260223102976/problems/994805270356541440

 

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

输入格式:

输入在第一行给出两个正整数 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 <bits/stdc++.h>
using namespace std;

int N, M;
int sum[1010];

struct Node {
    int score;
    int chos;
    string s;
    int wa;
    int num;
}node[1010];

bool cmp(const Node& a, const Node& b) {
    if(a.wa != b.wa)
        return a.wa > b.wa;
    else return a.num < b.num;
}

int main() {
    scanf("%d%d", &M, &N);
    for(int i = 0; i < N; i ++) {
        scanf("%d%d ", &node[i].score, &node[i].chos);
        getline(cin, node[i].s);
        node[i].num = i;
        sort(node[i].s.begin(), node[i].s.end());
    }

    vector<vector<string> > v;
    for(int i = 0; i < M; i ++) {
        string t;
        vector<string> row;
        getline(cin, t);
        int l = t.length();
        for(int j = 0; j < l; j ++) {
            if(t[j] == ‘(‘) {
                for(int k = j + 1; k < l; k ++)
                if(t[k] == ‘)‘) {
                    row.push_back(t.substr(j + 1, k - j - 1));
                    break;
                }
            }
        }
        v.push_back(row);
    }

    for(int i = 0; i < v.size(); i ++) {
        for(int j = 0; j < v[i].size(); j ++) {
            sort(v[i][j].begin(), v[i][j].end());
            if(v[i][j] == node[j].s)
                sum[i] += node[j].score;
            else node[j].wa ++;
        }
    }

    for(int i = 0; i < M; i ++)
        printf("%d\n", sum[i]);
    sort(node, node + N, cmp);
    if(node[0].wa == 0) printf("Too simple\n");
    else {
        printf("%d", node[0].wa);
        for(int i = 0; i < N; i ++) {
            if(node[i].wa == node[0].wa)
                printf(" %d", node[i].num + 1);
        }
    }
    return 0;
}

  

PAT 1058 选择题

标签:its   clu   多选   比较   int   string   题目   个学生   core   

原文地址:https://www.cnblogs.com/zlrrrr/p/10088086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!