题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805270356541440
思路:创建一个关于题目的结构体,含有题目分数、选项正确个数、错误次数、id的int成员和bool初始化为false,长度为6的数组(正确选项,a-0,b-1依次。false代表无该选项)。输入题目属性的时候,顺便初始化错误次数为零。设置一个bool类型判断某学生题目正确与否,首先与输入的选项个数对比,在对比选项。改题目正确则该学生加上相应的分数,否则该题目错误次数加一。最后将结构体排序(错误次数从大到小,若相同,id从小到大--sort,cmp),设置ma判断错误次数最多的题目以及没有题目错误。
#include <iostream>
#include <algorithm>
using namespace std;
const unsigned maxn = 1005;
struct St
{
int fs, cu, gs, id;
bool p[5] = {false};
} pro[105];
bool cmp(struct St a, struct St b)
{
if(a.cu == b.cu)
return a.id < b.id;
return a.cu > b.cu;
}
void solve()
{
int n, m;
cin>>n>>m;
for(int i = 0; i < m; i++)
{
int x;
cin>>pro[i].fs>>x>>pro[i].gs;
for(int j = 0; j < pro[i].gs; j++)
{
char f;
cin>>f;
pro[i].p[f - 'a'] = true;
}
pro[i].cu = 0;
pro[i].id = i + 1;
}
while(n--)
{
int re = 0;
for(int i = 0; i < m; i++)
{
char x;
cin>>x;
int h;
cin>>h;
bool fa = true;
if(h != pro[i].gs)
fa = false;
while(h--)
{
cin>>x;
if(!pro[i].p[x - 'a'])
fa = false;
}
cin>>x;
if(fa)
re += pro[i].fs;
else
pro[i].cu++;
}
cout<<re<<endl;
}
sort(pro, pro + m, cmp);
int ma = pro[0].cu;
if(ma == 0)
cout<<"Too simple"<<endl;
else
{
cout<<ma;
for(int i = 0; i < m; i++)
{
if(pro[i].cu != ma)
break;
cout<<" "<<pro[i].id;
}
cout<<endl;
}
}
int main()
{
solve();
return 0;
}
属于20分一般类,好像但是要注意细节
2018年9月17日 10:57:29