PAT 1062. Talent and Virtue (25) sort应用
2018-01-18 16:38
381 查看
/************************* 题意: 这个题意应该比较好理解吧 主要就是那些大于等于,大于之类的分清楚就行 ************************/ /************************ 这里我就利用了sort和vector,基本能解决大部分问题 *************************/ /*********************** 笔记: *********************/ #include<iostream> #include<stdio.h> #include<string> #include<vector> #include<queue> #include<stdlib.h> #include<algorithm> #include<string.h> #include<stack> #include<map> #include<unordered_map> using namespace std; #define M 110000 #define INF 0x7fffffff struct people{ int id,v,t; }; vector<people> sage,noble,fool,small; bool cmp(people a,people b){ if(a.t + a.v > b.t + b.v) return true; else if(a.t + a.v == b.t + b.v){ if(a.v > b.v) return true; else if(a.v == b.v){ if(a.t > b.t) return true; else if(a.t == b.t) return a.id <b.id; else return false; } else return false; } else return false; } int main(){ int n,low,high; cin>>n>>low>>high; int id,v,t,i; struct people p; for(i=0;i<n;i++){ scanf("%d%d%d",&id,&v,&t); p.id =id ;p.v =v; p.t =t; if(v>=low && t>=low){ if(v >= high && t >=high){ sage.push_back(p); } else if(v >= high && t<high){ noble.push_back(p); } else if(v<high && t<high && v >= t){ fool.push_back(p); } else small.push_back(p); } } vector<people> ans; sort(sage.begin(),sage.end(),cmp); sort(noble.begin(),noble.end(),cmp); sort(fool.begin(),fool.end(),cmp); sort(small.begin(),small.end(),cmp); cout<<sage.size()+noble.size()+fool.size()+small.size()<<endl; for(i=0;i<sage.size();i++) printf("%d %d %d\n",sage[i].id,sage[i].v,sage[i].t); for(i=0;i<noble.size();i++) printf("%d %d %d\n",noble[i].id,noble[i].v,noble[i].t); for(i=0;i<fool.size();i++) printf("%d %d %d\n",fool[i].id,fool[i].v,fool[i].t); for(i=0;i<small.size();i++) printf("%d %d %d\n",small[i].id,small[i].v,small[i].t); return 0; }
相关文章推荐
- PAT_B_1015. 德才论 (25) or PAT_A_1062. Talent and Virtue (25)
- PAT-A-1062. Talent and Virtue (25)
- pat 1062. Talent and Virtue (25)
- pat 1062. Talent and Virtue (25)
- PAT 1062. Talent and Virtue (25)
- PAT - 甲级 - 1062. Talent and Virtue (25)(排序)
- PAT 1062. Talent and Virtue (25)
- PAT 1062. Talent and Virtue (25)(判断是否是圣人君子小人)(代码超时)
- PAT-A 1062. Talent and Virtue (25)
- PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- 【C++】PAT (advanced level)1062. Talent and Virtue (25)
- 【PAT】【Advanced Level】1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
- PAT(甲级)1062. Talent and Virtue (25)
- PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- 【PAT】1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
- PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)
- PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)