0%

PAT A1062 Talent and Virtue

题目链接

解题思路

排序问题:使用自定义结构体,按照题目要求,分成几类人,设置标志位t,然后编写cmp函数,使用算法库的sort进行排序。

注意

1、not below是不小于也就是大于等于的意思!!!

2、cin,cout超时的话可以用printf和scanf,也可以加一句std::ios::sync_with_stdio(false);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=100010;
struct Man{
int t;//判断属于哪一类人
string id;
int vir,tal,total;
}men[maxn];
int n,L,H,k=0;

bool cmp(Man a,Man b){
if(a.t!=b.t) return a.t<b.t;
else if(a.total!=b.total) return a.total>b.total;
else if(a.vir!=b.vir) return a.vir>b.vir;
else return a.id<b.id;
}

int main(){
std::ios::sync_with_stdio(false);
cin>>n>>L>>H;
string s;
int v,t;
for(int i=0;i<n;i++){
cin>>s>>v>>t;
if(v<L||t<L) continue;
if(v>=H&&t>=H){
men[k].t=1;
}else if(v>=H&&t<H){
men[k].t=2;
}else if(v>=t){
men[k].t=3;
}else{
men[k].t=4;
}
men[k].id=s;men[k].vir=v;
men[k].tal=t;men[k].total=v+t;
k++;
}
sort(men,men+k,cmp);
cout<<k<<endl;
for(int i=0;i<k;i++){
cout<<men[i].id<<" "<<men[i].vir<<" "<<men[i].tal<<endl;
}
return 0;
}

本文标题:PAT A1062 Talent and Virtue

文章作者:GavinYGM

发布时间:2020年08月24日 - 14:08

最后更新:2020年08月24日 - 14:08

原始链接:http://www.gavinygm.cn/2020/08/24/PAT-A1062-Talent-and-Virtue/

许可协议: 转载请保留原文链接及作者。