当前位置: 代码迷 >> 综合 >> PAT甲级-1062 Talent and Virtue (25分)【同PAT乙级-1015】
  详细解决方案

PAT甲级-1062 Talent and Virtue (25分)【同PAT乙级-1015】

热度:97   发布时间:2023-09-26 23:13:38.0

点击链接PAT甲级-AC全解汇总

题目:
这道题和乙级1015一模一样,直接上链接:
PAT乙级-1015 德才论 (25分)

注意: 如果超时的话,重新提交试试看

我的代码:

#include<bits/stdc++.h>
using namespace std;
class Student
{
    
public:Student(){
    }Student(int id,int DE_score,int CAI_score){
    this->stu_id_=id;this->DE_score_=DE_score;this->CAI_score_=CAI_score;this->all_score_=DE_score+CAI_score;}~Student(){
    }Student& operator=(const Student& stu){
    stu_id_=stu.stu_id_;DE_score_=stu.DE_score_;CAI_score_=stu.CAI_score_;all_score_=stu.all_score_;return *this;}int stu_id_;int DE_score_;int CAI_score_;int all_score_;
};bool stucom(Student s1,Student s2)
{
    if(s1.all_score_!=s2.all_score_) return s1.all_score_>s2.all_score_;else if(s1.DE_score_!=s2.DE_score_) return s1.DE_score_>s2.DE_score_;else return s1.stu_id_<s2.stu_id_;
}int main()
{
    int N,L,H;cin>>N>>L>>H;Student a[N],b[N],c[N],d[N];int ia=0,ib=0,ic=0,id=0;for(int i=0;i<N;i++){
    int sid,de,cai;cin>>sid>>de>>cai;
// if(de<L||cai<L) continue;if(de>=H && cai>=H)a[ia++]=Student(sid,de,cai);else if(de>=H && cai>=L)b[ib++]=Student(sid,de,cai);else if(de>=L && cai>=L && de>=cai)c[ic++]=Student(sid,de,cai);else if(de>=L && cai>=L)d[id++]=Student(sid,de,cai);}sort(a,a+ia,stucom);sort(b,b+ib,stucom);sort(c,c+ic,stucom);sort(d,d+id,stucom);cout<<ia+ib+ic+id<<endl;
// printf("%d %d\n",L,H);
// printf("%d %d %d %d\n",ia,ib,ic,id);for(int i=0;i<ia;i++){
    cout<<a[i].stu_id_<<" "<<a[i].DE_score_<<" "<<a[i].CAI_score_<<endl;}for(int i=0;i<ib;i++){
    cout<<b[i].stu_id_<<" "<<b[i].DE_score_<<" "<<b[i].CAI_score_<<endl;}for(int i=0;i<ic;i++){
    cout<<c[i].stu_id_<<" "<<c[i].DE_score_<<" "<<c[i].CAI_score_<<endl;}for(int i=0;i<id;i++){
    cout<<d[i].stu_id_<<" "<<d[i].DE_score_<<" "<<d[i].CAI_score_<<endl;}return 0;
}