本文主要是介绍PAT(BASIC)1015. 德才论 (25),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//用cout老是运行超时,改用c风格的printf就可以了
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;struct data{unsigned id;unsigned de;unsigned cai;unsigned sum;
};bool comp(data d1,data d2){if(d1.sum>d2.sum)return true;else if(d1.sum<d2.sum)return false;else{if(d1.de>d2.de)return true;else if(d1.de<d2.de)return false;elsereturn d1.id<d2.id;}
}int main(void){unsigned n,l,h;cin>>n>>l>>h;vector<data> l1,l2,l3,l4;while(n--){data temp;cin>>temp.id>>temp.de>>temp.cai;temp.sum=temp.de+temp.cai;if((temp.de >= h) && (temp.cai >= h))l1.push_back(temp);else if((temp.de >= h) && (temp.cai >= l))l2.push_back(temp);else if((temp.de >= l) && (temp.cai >= l) && (temp.de >= temp.cai))l3.push_back(temp);else if((temp.de >= l) && (temp.cai >= l))l4.push_back(temp);}sort(l1.begin(),l1.end(),comp);sort(l2.begin(),l2.end(),comp);sort(l3.begin(),l3.end(),comp);sort(l4.begin(),l4.end(),comp);cout<<(l1.size()+l2.size()+l3.size()+l4.size())<<endl;for(auto i:l1)printf("%u %u %u\n",i.id,i.de,i.cai);for(auto i:l2)printf("%u %u %u\n",i.id,i.de,i.cai);for(auto i:l3)printf("%u %u %u\n",i.id,i.de,i.cai);for(auto i:l4)printf("%u %u %u\n",i.id,i.de,i.cai); system("pause");
}
这篇关于PAT(BASIC)1015. 德才论 (25)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!