题目:https://www.patest.cn/contests/pat-a-practise/1062
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct stu{
char id[10];
int vir;
int tal;
int sum;
int flag;
}s[100005];
bool cmp(stu a,stu b)
{
if(a.flag!=b.flag) return a.flag<b.flag;
else if(a.sum!=b.sum)return a.sum>b.sum;
else if(a.vir!=b.vir)return a.vir>b.vir;
else return strcmp(a.id,b.id)<0;
}
int main()
{
int n,min,max,i,count;
scanf("%d%d%d",&n,&min,&max);
count=n;
for(i=0;i<n;i++){
scanf("%s%d%d",&s[i].id,&s[i].vir,&s[i].tal);
s[i].sum=s[i].tal+s[i].vir;
if(s[i].vir<min||s[i].tal<min){
s[i].flag=5;
count--;
}
else if(s[i].vir>=max&&s[i].tal>=max) s[i].flag=1;
else if(s[i].vir>=max&&s[i].tal<max) s[i].flag=2;
else if(s[i].vir>=s[i].tal) s[i].flag=3;
else s[i].flag=4;
}
sort(s,s+n,cmp);
printf("%d\n",count);
for(i=0;i<count;i++){
printf("%s %d %d\n",s[i].id,s[i].vir,s[i].tal);
}
system("pause");
} #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct stu{
char id[10];
int vir;
int tal;
int sum;
int flag;
}s[100005];
bool cmp(stu a,stu b)
{
if(a.flag!=b.flag) return a.flag<b.flag;
else if(a.sum!=b.sum)return a.sum>b.sum;
else if(a.vir!=b.vir)return a.vir>b.vir;
else return strcmp(a.id,b.id)<0;
}
int main()
{
int n,min,max,i,count;
scanf("%d%d%d",&n,&min,&max);
count=n;
for(i=0;i<n;i++){
scanf("%s%d%d",&s[i].id,&s[i].vir,&s[i].tal);
s[i].sum=s[i].tal+s[i].vir;
if(s[i].vir<min||s[i].tal<min){
s[i].flag=5;
count--;
}
else if(s[i].vir>=max&&s[i].tal>=max) s[i].flag=1;
else if(s[i].vir>=max&&s[i].tal<max) s[i].flag=2;
else if(s[i].vir>=s[i].tal) s[i].flag=3;
else s[i].flag=4;
}
sort(s,s+n,cmp);
printf("%d\n",count);
for(i=0;i<count;i++){
printf("%s %d %d\n",s[i].id,s[i].vir,s[i].tal);
}
system("pause");
}