PAT Basic 1073. 多选题常见计分法

简介: 题目内容多选题常见计分法(20)时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Yue批改多选题是比较麻烦的事情,有很多不同的计分方法。

题目内容

  1. 多选题常见计分法(20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到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

题目解析

题目仅仅是麻烦点,算水题。
但是坑在于,如果用C++,读取数据,需要用getline的对吧,但是全部行都需要用getline吗,一开始我觉得第一行的m n两个数据不需要getline而是用cin读取,那么cin之后和getline之前插播一个getchar()就能正确处理了吧。

题目的坑就在这里,cin了m和n后还有个空格,所以需要两次getchar();但是不是每组测试用例都是在m和n后面有空格,所以有时候只需要一次getchar(),两次则报错。实际上,这里读取n和m,我用cin+一个getchar(),能过3,4,5组测试用例。用cin+两个getchar(),能过1,2组测试用例

我就无语了,为什么这么个小题,非要在这种蛋疼的地方卡人?不是我黑PAT,这种测试用例应该避免出现。

最后,全都换成getline()处理,然后在istringstream读入,就不报错了。

AC代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;

struct Timu {
    int score;
    int ans[5];
    int wrong_num[5];
    int num_of_choice;
    int num_of_ans;
    Timu(const string& s) {
        memset(ans, 0, sizeof(ans));
        memset(wrong_num, 0, sizeof(wrong_num));
        istringstream sin(s);
        sin >> score >> num_of_choice >> num_of_ans;
        char op;
        for (int i = 0; i < num_of_ans; i++) {
            sin >> op;
            ans[op - 'a'] = 1;
        }
    }
};

struct Stu {
    vector<vector<int> > ans;
    double score;
    Stu(const string& s) {
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '(' || s[i] == ')' || s[i] == ' ') {
                continue;
            }
            else if (isdigit(s[i])) {
                int num_of_choice = s[i] - '0';
                vector<char> cc;
                i += 2;
                vector<int> t_ans(5, 0);
                for (int j = 0; j < num_of_choice; j++, i += 2) {
                    t_ans[s[i] - 'a'] = 1;
                }
                ans.push_back(t_ans);
            }
        }
    }
};

void do_calc(vector<Timu>& vtimu, vector<Stu>& vstu) {
    for (int i = 0; i < vstu.size(); i++) {
        vstu[i].score = 0;
        for (int j = 0; j < vtimu.size(); j++) {
            int right_cnt = 0;
            bool wuxuan = false;

            // 标记误选和漏选
            for (int k = 0; k < vtimu[j].num_of_choice; k++) {
                if (vtimu[j].ans[k]==vstu[i].ans[j][k]) {
                    right_cnt++;
                }
                else {
                    vtimu[j].wrong_num[k]++;
                    if (vtimu[j].ans[k] == 0) {
                        wuxuan = true;
                    }
                }
            }

            double t_score = 0;
            if (right_cnt == vtimu[j].num_of_choice) {
                t_score = vtimu[j].score;
            }
            else if (!wuxuan) { //部分正确,有漏选
                t_score = 0.5 * vtimu[j].score;
            }
            vstu[i].score += t_score;
            //cout << "student[" << i << "] has: right_cnt=" << right_cnt << ", wrong_cnt=" << wrong_cnt << ", get score=" << t_score << endl;
        }
    }
}

string int2str(int a) {
    stringstream ss;
    string res;
    ss << a;
    ss >> res;
    return res;
}

vector<string> do_stat(const vector<Timu>& vtimu) {
    int max_val = 0;
    for (int i = 0; i < vtimu.size(); i++) {
        for (int j = 0; j < vtimu[i].num_of_choice; j++) {
            if (vtimu[i].wrong_num[j] > max_val) {
                max_val = vtimu[i].wrong_num[j];
            }
        }
    }
    vector<string> res;
    string rr = "";
    if (max_val == 0) {
        rr = "Too simple";
        res.push_back(rr);
        return res;
    }
    else {
        for (int i = 0; i < vtimu.size(); i++) {
            //cout << ">> vtimu[" << i << "].num_of_wrong_select are: ";
            for (int j = 0; j < vtimu[i].num_of_choice; j++) {
                //cout << vtimu[i].num_of_wrong_select[j] << " ";
                if (vtimu[i].wrong_num[j] == max_val) {
                    rr = int2str(vtimu[i].wrong_num[j]) + " " + int2str(i + 1) + "-" + char(j + 'a');
                    res.push_back(rr);
                }
            }
            //cout << endl;
        }
        return res;
    }
}

int main() {
    string line;
    int n, m;
        // 这里读取n和m,我用cin+一个getchar(),能过3,4,5组测试用例
        // 用cin+两个getchar(),能过1,2组测试用例
    getline(cin, line);
    istringstream sin(line);
    sin >> n >> m;
    
    vector<Timu> vtimu;
    for (int i = 0; i < m; i++) {
        getline(cin, line);
        vtimu.push_back(Timu(line));
        //cout << "timu: " << line << endl;
    }
    vector<Stu> vstu;
    for (int i = 0; i < n; i++) {
        getline(cin, line);
        vstu.push_back(Stu(line));
        //cout << "student: " << line << endl;
    }
    do_calc(vtimu, vstu);
    for (int i = 0; i < vstu.size(); i++) {
        printf("%.1lf\n", vstu[i].score);
    }
    vector<string> res = do_stat(vtimu);
    for (int i = 0; i < res.size(); i++) {
        cout << res[i] << endl;
    }

    return 0;
}
目录
相关文章
|
11月前
|
C语言 C++
PAT (Basic Level) Practice (中文)1099 性感素数(20分)
“性感素数”是指形如 (p, p+6) 这样的一对素数。之所以叫这个名字,是因为拉丁语管“六”叫“sex”(即英语的“性感”)。(原文摘自 http://mathworld.wolfram.com/SexyPrimes.html) 现给定一个整数,请你判断其是否为一个性感素数。
94 0
|
11月前
|
C语言 C++
PAT (Basic Level) Practice (中文) 1031 查验身份证 (15分)
一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:
54 0
|
测试技术
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
97 0
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
|
算法
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
78 0
|
存储 测试技术
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
64 0
|
存储
PAT (Basic Level) Practice (中文) 1041 考试座位号 (15 分)
PAT (Basic Level) Practice (中文) 1041 考试座位号 (15 分)
65 0
PAT (Basic Level) Practice (中文) 1041 考试座位号 (15 分)
PAT (Basic Level) Practice (中文) 1036 跟奥巴马一起编程 (15 分) p89
PAT (Basic Level) Practice (中文) 1036 跟奥巴马一起编程 (15 分) p89
128 0
PAT (Basic Level) Practice (中文) 1010 一元多项式求导 (25 分)
PAT (Basic Level) Practice (中文) 1010 一元多项式求导 (25 分)
72 0
PAT (Basic Level) Practice (中文)- 1073 多选题常见计分法(20 分)
PAT (Basic Level) Practice (中文)- 1073 多选题常见计分法(20 分)
106 0
|
编译器
PAT (Basic Level) Practice (中文)- 1077 互评成绩计算(20 分)
PAT (Basic Level) Practice (中文)- 1077 互评成绩计算(20 分)
80 0