1058 选择题 (20 分)
题目链接
算法分析
我的算法主要有两点
1.开一个标记数组on【300】(acii最大就255),标记为1,便于后续判断是否为正确答案
2.结构体数组排序,并特判后输出。
代码实现
#include<bits/stdc++.h>
using namespace std;
struct que{
int mx;//满分
int id;//题目号
int wrong;//错误人数
int true_cnt;//该题正确选项的数目
int on[300];标记正确答案的数组
}ques[105];
bool cmp(que a, que b){//比较函数
if(a.wrong != b.wrong) return a.wrong > b.wrong;
else return a.id < b.id;
}
int main(){
char s;//临时变量
int n, m;
int x, y, z;//临时变量
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++ i){
ques[i].id = i;
scanf("%d%d%d", &x, &y, &z);//第二个变量后面用不到
ques[i].mx = x;
ques[i].true_cnt = z;
while((s = getchar()) != '\n')
if(islower(s))
ques[i].on[(int)s] = 1;//标记正确答案
}
int cnt, sum;
bool flag, judge = 1;
for(int i = 1; i <= n; ++ i){
//每一个人都要初始化
cnt = 0;//当前题目序号
sum = 0;//当前已获总分
while((s = getchar()) != '\n'){
if(s == '('){
cnt ++;//题目号加1
flag = 1;//暂时标记为本题回答正确
}
else if(isdigit(s)){
if(s - '0' != ques[cnt].true_cnt)
flag = 0;//如果选项个数不匹配,回答错误
}
else if(s == ' ') continue;
else if(islower(s)){
if(!ques[cnt].on[(int)s]){
flag = 0;//如果有的选项不对,回答错误
}
}
else if(s == ')'){//统计本题回答的情况
if(flag) sum += ques[cnt].mx;
else{
ques[cnt].wrong ++;
judge = 0;
}
}
}
printf("%d\n", sum);//输出这个人的总分
}
if(judge) puts("Too simple");
else{
sort(ques + 1, ques + m + 1, cmp);
printf("%d %d", ques[1].wrong, ques[1].id);
int t = 2;//错误数量并列,则输出编号(递增)
while(ques[t].wrong == ques[1].wrong){
printf(" %d", ques[t].id);
t ++;
}
}
return 0;
}