[PAT] Class 1062 Talent and Virtue (25 points)

Meaning of the questions:

Input three positive integer N, L, H (N <= 1E5, L> = 60, H <100, H> L), representing the number, the pass line and high level line. Then the input data of N rows, each row including ID, and moral values ​​to values ​​of a person. When a person's moral and to not less than H as a saint, morality is not less than H to L is not less than nobility, morality, and to not less than as fools, ethical and moral order and when L is not less than before when not less than L and moral order is lower than the villain (the priority determination saint, saint can be higher than moral). Respectively, in their own sort within groups where, in accordance with the moral order sum descending order, the second priority is a number in descending order, the third priority is the id of the ascending order. The total number of people ordered by questions intended output and the output of their information.

Code:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct student{
string id;
int v,t;
int sum;
};
student sage[100007],noble[100007],fool[100007],small[100007];
bool cmp(student a,student b){
if(a.sum!=b.sum)
return a.sum>b.sum;
if(a.v!=b.v)
return a.v>b.v;
return a.id<b.id;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,l,h;
cin>>n>>l>>h;
int cnt1=0,cnt2=0,cnt3=0,cnt4=0;
for(int i=1;i<=n;++i){
string id;
cin>>id;
int v,t;
cin>>v>>t;
if(v>=h&&t>=h){
sage[++cnt1].id=id;
sage[cnt1].v=v;
sage[cnt1].t=t;
sage[cnt1].sum=v+t;
}
else if(v>=h&&t>=l){
noble[++cnt2].id=id;
noble[cnt2].v=v;
noble[cnt2].t=t;
noble[cnt2].sum=v+t;
}
else if(v>=l&&t>=l&&v>=t){
fool[++cnt3].id=id;
fool[cnt3].v=v;
fool[cnt3].t=t;
fool[cnt3].sum=v+t;
}
else if(v>=l&&t>=l&&v<t){
small[++cnt4].id=id;
small[cnt4].v=v;
small[cnt4].t=t;
small[cnt4].sum=v+t;
}
}
sort(sage+1,sage+1+cnt1,cmp);
sort(noble+1,noble+1+cnt2,cmp);
sort(fool+1,fool+1+cnt3,cmp);
sort(small+1,small+1+cnt4,cmp);
cout<<cnt1+cnt2+cnt3+cnt4<<"\n";
for(int i=1;i<=cnt1;++i)
cout<<sage[i].id<<" "<<sage[i].v<<" "<<sage[i].t<<"\n";
for(int i=1;i<=cnt2;++i)
cout<<noble[i].id<<" "<<noble[i].v<<" "<<noble[i].t<<"\n";
for(int i=1;i<=cnt3;++i)
cout<<fool[i].id<<" "<<fool[i].v<<" "<<fool[i].t<<"\n";
for(int i=1;i<=cnt4;++i)
cout<<small[i].id<<" "<<small[i].v<<" "<<small[i].t<<"\n";
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11750146.html
Recommended