所有的坑都试了一遍,还是没找到哪错了,唉…
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=5;
struct record{
char id[10];
int test_num;
int test_score;
}records[100005];
struct student{
char id[10];
int total_score=0;
int test_score[5]={-2,-2,-2,-2,-2};
int AC=0;
int flag=0;
int rank=0;
}stu[1005];
bool cmp1(record a, record b){
if(strcmp(a.id,b.id)!=0) return strcmp(a.id,b.id)<0;
else if(a.test_num!=b.test_num) return a.test_num<b.test_num;
else return a.test_score>b.test_score;
}
bool cmp2(student a, student b){
if(a.flag!=b.flag) return a.flag>b.flag;
else if(a.total_score!=b.total_score) return a.total_score>b.total_score;
else if(a.AC!=b.AC) return a.AC>b.AC;
else return strcmp(a.id,b.id)<0;
}
int main(){
int n, total_test_num, sub_num;
scanf("%d %d %d", &n, &total_test_num, &sub_num);
int value[maxn];
for(int i=0;i<total_test_num;i++){
scanf("%d", &value[i]);
}
for(int i=0;i<sub_num;i++){
scanf("%s %d %d",records[i].id,&records[i].test_num,&records[i].test_score);
}
sort(records,records + sub_num,cmp1);
strcpy(stu[0].id,records[0].id);
int test_num;
for(int i=0,j=0,k;i<sub_num;i++){
if(strcmp(records[i].id,stu[j].id)!=0){
strcpy(stu[++j].id,records[i].id);
}
test_num = records[i].test_num;
if(stu[j].test_score[test_num-1]==-2){
if(records[i].test_score!=-1){
stu[j].flag=1;
stu[j].test_score[test_num-1]=records[i].test_score;
stu[j].total_score +=stu[j].test_score[test_num-1];
if(stu[j].test_score[test_num-1]==value[test_num-1]) stu[j].AC++;
}else{
stu[j].test_score[test_num-1]=0;
}
}
}
sort(stu,stu+n,cmp2);
int isHave = 1;
for(int i=0;i<n;i++){
if(stu[i].flag==0){
if(i==0) isHave=0;
break;
}else{
if(i!=0 && stu[i].total_score==stu[i-1].total_score){
stu[i].rank=stu[i-1].rank;
}else{
stu[i].rank=i+1;
}
printf("%d %s %d",stu[i].rank,stu[i].id,stu[i].total_score);
for(int j=0;j<total_test_num;j++){
if(stu[i].test_score[j]==-2) printf(" -");
else printf(" %d",stu[i].test_score[j]);
}
printf("\n");
}
}
return 0;
}
|