[Grade] PAT 1075 PAT Judge (25 minutes)

Meaning of the questions:

Input three positive integer N, K, M (N <= 10000, K <= 5, M <= 100000), then the input line represents the positive integer K out of the question, then the input data is M rows, each row comprising student ID (five integer of 1 ~ N), and the title number of the title score (-1 means no compile). Scoring output rankings, student ID, and the total score for each question, the first priority is descending score, the second priority is the subject of AC descending order, the third priority is the student ID in ascending order (but not submitted by compiling a score of 0, no submit score - no output not submitted or not submitted by all student information compiled).

trick:

4 test points for the students to have to pay to get points after the title of a program and later paid a program does not compile, pay attention branch structure will not go wrong.

Code:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct student{
int id;
int score[7];
int sum;
int num;
};
student a[10007],b[10007];
int total[7];
bool cmp(student x,student y){
if(x.sum!=y.sum)
return x.sum>y.sum;
if(x.num!=y.num)
return x.num>y.num;
return x.id<y.id;
}
int main(){
//ios::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
int n,k,m;
scanf("%d%d%d",&n,&k,&m);
for(int i=1;i<=n;++i){
for(int j=1;j<=k;++j){
a[i].score[j]=-1;
}
}
for(int i=1;i<=k;++i)
scanf("%d",&total[i]);
for(int i=1;i<=m;++i){
int id,num,val;
scanf("%d%d%d",&id,&num,&val);
if(val>-1)
a[id].id=id;
else if(a[id].score[num]<0)
a[id].score[num]=0;
if(val>a[id].score[num])
a[id].score[num]=val;
}
int cnt=0;
for(int i=1;i<=n;++i){
if(a[i].id){
b[++cnt]=a[i];
for(int j=1;j<=k;++j){
b[cnt].sum+=max(0,b[cnt].score[j]);
if(b[cnt].score[j]==total[j])
++b[cnt].num;
}
}
}
sort(b+1,b+1+cnt,cmp);
int rank_=0;
b[0].sum=1e9;
for(int i=1;i<=cnt;++i){
if(b[i].sum<b[i-1].sum)
rank_=i;
printf("%d %05d %d",rank_,b[i].id,b[i].sum);
for(int j=1;j<=k;++j){
if(b[i].score[j]==-1)
printf(" -");
else
printf(" %d",b[i].score[j]);
}
printf("\n");
}
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11811202.html