PAT 1058 选择题 (20 分)

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main() {
    int stu,mcq,temp,corrop;                     //学生人数,多选题个数,选项个数,正确选项的个数
    cin>>stu>>mcq;
    vector<set<char>> right(mcq);               //right集合组保存正确答案
    vector<int>total(mcq),wrongCnt(mcq);         //每题分值total[i],错误次数wrongCnt[i]
    for(int i=0;i<mcq;i++){                //输入正确答案保存到right
        scanf("%d%d%d", &total[i], &temp, &corrop);
        for(int j = 0; j < corrop; j++) {
            char c;
            cin>>c;
            right[i].insert(c);
        }
    
    }
    for(int i=0;i<stu;i++){            	//输入每个学生答案到st组中
        int score=0;
        scanf("\n");                   //读入字符前把缓冲区的换行符匹配掉,第一次循环读入的是数字所以会自动忽略
        for(int j=0;j<mcq;j++){
            if(j!=0) scanf(" ");
            scanf("(%d",&temp);         //学生的选中个数temp
            set<char> st;
            char c;
            for(int k=0;k<temp;k++){        //每题读入temp个选中的选项到st中
                scanf(" %c",&c);
                st.insert(c);
            }
            scanf(")");
            if(right[j]==st){            //该题st[j]学生答案和正确答案right[j]对比
                score+=total[j];
            }else{
                wrongCnt[j]++;
            }
        }
        cout<<score<<endl;
    }
    int maxWrongCnt = 0;
    for(int i = 0; i < mcq; i++) {
        if(wrongCnt[i] > maxWrongCnt) {
            maxWrongCnt = wrongCnt[i];
        }
    }
    if(maxWrongCnt == 0)
       cout<<"Too simple";
    else{
        cout<<maxWrongCnt;
        for(int i=0;i<mcq;i++){
            if(wrongCnt[i]==maxWrongCnt)
            cout<<" "<<i+1;
        }
    }
    system("pause");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值