自己菜,写不出来,以下是柳神大佬代码~
分析: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输⼊入,否则可能接收成空格或者空值~
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
int main()
{
int n, m, t, 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], &t, &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;
}