PAT basic 1058

来源:互联网 发布:诺亚方舟 知乎 编辑:程序博客网 时间:2024/05/30 22:42
#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;}/*分析: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的那些题号~~*/
原创粉丝点击