https://pintia.cn/problem-sets/994805260223102976/problems/994805263624683520
繁杂的题。先是没看清题意,后面要注意好多细节。
#include<iostream>
#include<string.h>
using namespace std;
struct{
int score;
int right_opt[5]={0};
int wrong_opt[5]={0};
int right=0;
}ques[100];
int main() {
char ch;
int n, m, nouse, start=0, k, flag, len, length;
int cmp[5]={0,0,0,0,0}, options[5], max=0, p=0;
string str;
float score;
cin >> n >> m;
// 正确答案
for(int i=0; i<m; i++){
cin >> ques[i].score >> nouse >> len;
for(int j=0; j<len; j++){
cin >> ch;
ques[i].right_opt[ch-97]=1;
ques[i].right++;
}
}
// 每个学生答案
for(int i=0; i<n; i++){
cin.clear();
cin.ignore();
k = 0;
score = 0;
while(cin.peek()!='\n'){
cin >> ch;
if(ch == '(' && start == 0){
start = 1;
flag = 1;
memcpy(options, cmp, sizeof(cmp));
}else if(ch >= '0' && ch <= '5' && start == 1){
length = ch - '0';
}else if(ch >= 'a' && ch <= 'e' && start == 1){
options[ch-97] = 1;
if(ques[k].right_opt[ch-97] == 0)
flag = 0;
}else if(ch == ')' && start == 1){
start = 0;
// 计算得分
if(flag == 1 && ques[k].right == length){// 全对
score += ques[k].score*1.0;
}else if(flag == 1 && ques[k].right != length){// 半对
score += ques[k].score*1.0/2;
}
// 最多错误选项
for(int j=0; j<5; j++){
if(ques[k].right_opt[j] != options[j]){
ques[k].wrong_opt[j]++;
if(ques[k].wrong_opt[j] > max){
max = ques[k].wrong_opt[j];
}
}
}
k ++;
}
}
printf("%.1f\n", score);
}
if(max==0){
cout << "Too simple" << endl;
}
for(int i=0; i<m && max>0; i++){
for(int j=0; j<5; j++){
if(ques[i].wrong_opt[j]==max){
cout << max << " " << i+1 << "-" << char(j+97) << endl;
}
}
}
return 0;
}