#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Person{
int name;//编号
int num;// 抢到的红包数
int sum;//抢到的红包个数
}p[10001];
bool cmp(Person p1,Person p2){
if(p1.sum!=p2.sum){
return p1.sum>p2.sum;
}
else if(p1.num!=p2.num){
return p1.num>p2.num;
}
else{
return p1.name<p2.name;
}
}
int main(){
int t,n,a,b;
cin>>t;
for(int i=1 ;i<=t ;i++){
p[i].name = i;//编号初始化
}
for(int i=1 ;i<=t ; i++){
cin>>n;
while(n--){
scanf("%d%d",&a,&b);
p[i].sum-=b;//发红包的人减少的个数
p[a].sum += b;
p[a].num++;
}
}
sort(p+1,p+t+1,cmp);
for(int i=1 ;i<=t ;i++){
printf("%d %.2f\n",p[i].name,(double)p[i].sum/100.00);
}
return 0;
}
10-排序5 PAT Judge (25分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.
Input Specification:
Each input file contains one test case. For each case, the first line contains 3 positive integers, NNN (≤104\le 10^4≤104), the total number of users, KKK (≤5\le 5≤5), the total number of problems, and MMM (≤105\le 10^5≤105), the total number of submissions. It is then assumed that the user id's are 5-digit numbers from 00001 to NNN, and the problem id's are from 1 to KKK. The next line contains KKK positive integers p[i]
(i
=1, ..., KKK), where p[i]
corresponds to the full mark of the i-th problem. Then MMM lines follow, each gives the information of a submission in the following format:
user_id problem_id partial_score_obtained
where partial_score_obtained
is either −1-1−1 if the submission cannot even pass the compiler, or is an integer in the range [0, p[problem_id]
]. All the numbers in a line are separated by a space.
Output Specification:
For each test case, you are supposed to output the ranklist in the following format:
rank user_id total_score s[1] ... s[K]
where rank
is calculated according to the total_score
, and all the users with the same total_score
obtain the same rank
; and s[i]
is the partial score obtained for the i
-th problem. If a user has never submitted a solution for a problem, then "-" must be printed at the corresponding position. If a user has submitted several solutions to solve one problem, then the highest score will be counted.
The ranklist must be printed in non-decreasing order of the ranks. For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems. And if there is still a tie, then they must be printed in increasing order of their id's. For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist. It is guaranteed that at least one user can be shown on the ranklist.
Sample Input:
7 4 20
20 25 25 30
00002 2 12
00007 4 17
00005 1 19
00007 2 25
00005 1 20
00002 2 2
00005 1 15
00001 1 18
00004 3 25
00002 2 25
00005 3 22
00006 4 -1
00001 2 18
00002 1 20
00004 1 15
00002 4 18
00001 3 4
00001 4 2
00005 2 -1
00004 2 0
Sample Output:
1 00002 63 20 25 - 18
2 00005 42 20 0 22 -
2 00007 42 - 25 - 17
2 00001 42 18 18 4 2
5 00004 40 15 0 25 -
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct stu //学生结构
{
int id; //id
int s[5]; //各题分数,内部从0开始编号
int score; //总分
int pass; //完全正确题目数
int ns; //无提交或无任何通过编译标志,0代表没有通过
stu() //初始化
{
id=0;score=0;pass=0;ns=0;
for(int i=0;i<5;i++)
s[i]=-2; //由于输出要求,对没有处理过的用-2表示
}
};
bool cm(const stu &s1,const stu &s2); //比较
int main()
{
int n,k,m;
cin>>n>>k>>m;
stu *student=new stu [n]; //学生,标号i对应真实id-1
int p[5]; //分门分数
int i,j;
for(i=0;i<k;i++) //输入信息
scanf("%d",&p[i]);
int id,p_id,ps;
for(i=0;i<m;i++)
{
scanf("%d %d %d",&id,&p_id,&ps);
if(ps>student[id-1].s[p_id-1])
student[id-1].s[p_id-1]=ps;
}
for(i=0;i<n;i++) //计算总分,完全正确题目数,是否需要剔除
{
student[i].id=i+1;
for(j=0;j<k;j++)
{
if(student[i].s[j]>=0)
{
student[i].score+=student[i].s[j];
student[i].ns=1;
}
if(student[i].s[j]==p[j])
student[i].pass++;
}
}
stable_sort(student,student+n,cm); //稳定排序,可以免去一次id比较
int rank=1; //当前的名次,处理并列用
int score=student[0].score; //当前的分数
for(i=0;i<n;i++)
{
if(student[i].ns==0) //到达无用数据段跳出
break;
if(student[i].score!=score) //不是并列,刷新分数
{
rank=i+1;
score=student[i].score;
}
printf("%d %05d %d",rank,student[i].id,student[i].score); //输出信息
for(j=0;j<k;j++)
{
if(student[i].s[j]>=0)
printf(" %d",student[i].s[j]);
else if(student[i].s[j]==-1)
printf(" 0");
else
printf(" -");
}
printf("\n");
}
delete [] student;
return 0;
}
bool cm(const stu &s1,const stu &s2) //按总分和完全正确题目数排序用比较
{
if(s1.score>s2.score)
return true;
else if(s1.score==s2.score)
return s1.pass>s2.pass;
else
return false;
}