Sample Input
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
Sample Output
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
思路: 德才兼备方为大家。
这题就考排序,用c写比较麻烦,直接用c++的sort函数 + cmp函数写,会快很多,思路也简单。
注意一定要小心,这个的排序因素还是比较多的。
代码
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct score{
char num[10];
int de;
int cai;
int sum;
int rank;
}s1,s2[100005];
bool cmp(score x,score y){
if(x.rank!=y.rank){
return x.rank<y.rank;
}
else if(x.sum!=y.sum){
return x.sum>y.sum;
}
else if(x.de!=y.de){
return x.de>y.de;
}
else{
return strcmp(x.num,y.num)<0;
}
}
int main()
{
int n,l,h;
scanf("%d %d %d",&n,&l,&h);
int i;
int f=0;
for(i=0;i<n;i++){
scanf("%s %d %d",s1.num,&s1.de,&s1.cai);
if(s1.de>=l&&s1.cai>=l){
s2[f]=s1;
s2[f].sum=s2[f].de+s2[f].cai;
if(s2[f].de>=h&&s2[f].cai>=h){
s2[f].rank=1;
}
else if(s2[f].de>=h&&s2[f].cai<h){
s2[f].rank=2;
}
else if(s2[f].de>=s2[f].cai&&s2[f].de<h&&s2[f].cai<h){
s2[f].rank=3;
}
else{
s2[f].rank=4;
}
f++;
}
}
sort(s2,s2+f,cmp);
printf("%d\n",f);
for(i=0;i<f;i++){
printf("%s %d %d\n",s2[i].num,s2[i].de,s2[i].cai);
}
return 0;
}