1058 选择题 (20 分)

1058

分析

分析:n个学生,m道题目。对于每一道题目,将题目的总分存储在total[i]数组里面,将题目的选项插入存储在right[i](为集合类型)里面。wrongCnt[i]存储第i道题错误的人数,对于n个学生,每一个学生的答案插入一个集合st里面,比较st与right[i]是否相等,如果相等说明该生答对了,他的score += total[i](加上当前题目的总分),如果该生答错了,wrongCnt[i]++,表示第i道题新增一个错误的人。输出每一个学生的得分;遍历wrongCnt数组,求wrongCnt的最大值maxWrongCnt。如果maxWrongCnt == 0说明没有一个人做错题目,则输出“Too simple”,否则输出maxWrongCnt的值,和wrongCnt数组中wrongCnt[i] == maxWrongCnt的那些题号~

注意:scanf中的%d和%c之间一定要有分隔符的主动scanf输入,否则可能接收成空格或者空值~

题解

柳神分析
又是抄柳神答案的一天0.0

#include <cstdio>
#include <vector>
#include <set>
using namespace std;
int main() {
    int n, m, temp, k;
    scanf("%d%d", &n, &m);
    vector<set<char>> right(m);
    vector<int> total(m), wrongCnt(m);
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &total[i], &temp, &k);
        for(int j = 0; j < k; j++) {
            char c;
            scanf(" %c", &c);
            right[i].insert(c);
        }
    }
    for(int i = 0; i < n; i++) {
        int score = 0;
        scanf("\n");
        for(int j = 0; j < m; j++) {
            if(j != 0) scanf(" ");
            scanf("(%d", &k);
            set<char> st;
            char c;
            for(int l = 0; l < k; l++) {
                scanf(" %c", &c);
                st.insert(c);
            }
            scanf(")");
            if(st == right[j]) {
                score += total[j];
            } else {
                wrongCnt[j]++;
            }
        }
        printf("%d\n", score);
    }
    int maxWrongCnt = 0;
    for(int i = 0; i < m; i++) {
        if(wrongCnt[i] > maxWrongCnt) {
            maxWrongCnt = wrongCnt[i];
        }
    }
    if(maxWrongCnt == 0)
        printf("Too simple");
    else {
        printf("%d", maxWrongCnt);
        for(int i = 0; i < m; i++) {
            if(wrongCnt[i] == maxWrongCnt) {
                printf(" %d", i + 1);
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值