将每道题目按照序号打表,然后将学生的选择和表对比。
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
struct problem{
int score;
int totalnum;
int correnum;
int beicuocishu;
}p;
struct student{
int score;
}s;
map<int, string> numtostr;
int main(){
int N, M, k,maxncishu=0;
char a;
int mark;
scanf("%d %d",&N,&M);
vector<problem> vec;
vector <student> stu;
string str;
string str2;
string str3;
for(int i=0; i<N;i++){
s.score=0;
stu.push_back(s);
}
for(int i=0; i<M;i++){
str.clear();
scanf("%d %d %d",&p.score,&p.totalnum,&p.correnum);
k=0;
str2=p.correnum+'0'; //将数字保存为string格式
str=str+str2; //operator+- string with string
while(scanf("%c",&a),a!='\n'){
if(a!=' '){
str=str+a; //operator+- string with char or char[];
}
}p.beicuocishu=0;
vec.push_back(p);
numtostr[i]=str;
// cout << str <<"\n";
}
str2.clear();
for(int i=0; i<N; i++){
// str.clear();
getline(cin,str); //string里的字符会被清空,不需要提前clear
int k=0;
for(int j=0; j< M; j++){
for(k++; str[k]!=')';k++){
if(str[k]!='(' && str[k]!=' '){
str2=str2+str[k]; //operator+- str with str[]
}
}
// cout << str2 <<"\n";
if(str2 != numtostr[j]) {
vec[j].beicuocishu++;
maxncishu=vec[j].beicuocishu>maxncishu?vec[j].beicuocishu:maxncishu;
}else{
stu[i].score+=vec[j].score;
}
str2.clear();
}
}
for(int i=0; i<N; i++){
printf("%d\n",stu[i].score);
}
if(maxncishu==0) printf("Too simple");
else{
printf("%d",maxncishu);
for(int j=0;j<M; j++){
if(vec[j].beicuocishu==maxncishu) printf(" %d",j+1);
}
}
return 0;
}
转载须注明出处。