生活随笔
收集整理的這篇文章主要介紹了
【PAT乙级】 1015 德才论 (25 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://pintia.cn/problem-sets/994805260223102976/problems/994805307551629312
第一類 都過線了 總分排序
第二類 德過才不過 總分排序
第三類 都低于H 德大于等于才 總分排序
第四類 都低于H 總分排序
先總分排
總分相同 按德分排 德分相同按準考證號小到大
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std
;
const int N
=1e5+10;
struct student
{int id
;int a
,b
;
}temp
;
int n
,L
,H
;
vector
<student
>v1
,v2
,v3
,v4
;
bool cmp(student a
,student b
)
{if(a
.a
+a
.b
==b
.a
+b
.b
){if(a
.a
==b
.a
) return a
.id
<b
.id
;return a
.a
>b
.a
;}return a
.a
+a
.b
>b
.a
+b
.b
;
}
int main(void)
{cin
>>n
>>L
>>H
;for(int i
=0;i
<n
;i
++){cin
>>temp
.id
>>temp
.a
>>temp
.b
;if(temp
.a
>=L
&&temp
.b
>=L
){if(temp
.a
>=H
&&temp
.b
>=H
) v1
.push_back(temp
);else if(temp
.a
>=H
&&temp
.b
<H
) v2
.push_back(temp
);else if(temp
.a
>=temp
.b
) v3
.push_back(temp
);else v4
.push_back(temp
);}}cout
<<v1
.size()+v2
.size()+v3
.size()+v4
.size()<<endl
;sort(v1
.begin(),v1
.end(),cmp
);sort(v2
.begin(),v2
.end(),cmp
);sort(v3
.begin(),v3
.end(),cmp
);sort(v4
.begin(),v4
.end(),cmp
);for(int i
=0;i
<v1
.size();i
++) cout
<<v1
[i
].id
<<" "<<v1
[i
].a
<<" "<<v1
[i
].b
<<endl
;for(int i
=0;i
<v2
.size();i
++) cout
<<v2
[i
].id
<<" "<<v2
[i
].a
<<" "<<v2
[i
].b
<<endl
;for(int i
=0;i
<v3
.size();i
++) cout
<<v3
[i
].id
<<" "<<v3
[i
].a
<<" "<<v3
[i
].b
<<endl
;for(int i
=0;i
<v4
.size();i
++) cout
<<v4
[i
].id
<<" "<<v4
[i
].a
<<" "<<v4
[i
].b
<<endl
;return 0;
}
總結
以上是生活随笔為你收集整理的【PAT乙级】 1015 德才论 (25 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。