PAT甲题题解-1062. Talent and Virtue (25)-排序水题
2017-03-03 15:44
183 查看
水题,分组排序即可。
View Code
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; /* 太水水水。。。 */ const int maxn=100000+5; int cnt1,cnt2,cnt3,cnt4; struct Node{ int id; int tot; int vir; int tal; bool operator<(const Node tmp)const{ if(tot==tmp.tot){ if(vir==tmp.vir) return id<tmp.id; else return vir>tmp.vir; } else return tot>tmp.tot; } }sages[maxn],noble[maxn],fool[maxn],small[maxn]; int main() { int n,L,H; int a,b,c; scanf("%d %d %d",&n,&L,&H); for(int i=1;i<=n;i++){ scanf("%d %d %d",&a,&b,&c); if(b<L || c<L) continue; if(b>=H && c>=H){ sages[cnt1].id=a; sages[cnt1].vir=b; sages[cnt1].tal=c; sages[cnt1].tot=b+c; cnt1++; } else if(b>=H && c<H && c>=L){ noble[cnt2].id=a; noble[cnt2].vir=b; noble[cnt2].tal=c; noble[cnt2].tot=b+c; cnt2++; } else if(b<H && c<H &&b>=c){ fool[cnt3].id=a; fool[cnt3].vir=b; fool[cnt3].tal=c; fool[cnt3].tot=b+c; cnt3++; } else{ small[cnt4].id=a; small[cnt4].vir=b; small[cnt4].tal=c; small[cnt4].tot=b+c; cnt4++; } } sort(sages,sages+cnt1); sort(noble,noble+cnt2); sort(fool,fool+cnt3); sort(small,small+cnt4); printf("%d\n",cnt1+cnt2+cnt3+cnt4); for(int i=0;i<cnt1;i++){ printf("%08d %d %d\n",sages[i].id,sages[i].vir,sages[i].tal); } for(int i=0;i<cnt2;i++){ printf("%08d %d %d\n",noble[i].id,noble[i].vir,noble[i].tal); } for(int i=0;i<cnt3;i++){ printf("%08d %d %d\n",fool[i].id,fool[i].vir,fool[i].tal); } for(int i=0;i<cnt4;i++){ printf("%08d %d %d\n",small[i].id,small[i].vir,small[i].tal); } return 0; }
View Code
相关文章推荐
- PAT - 甲级 - 1062. Talent and Virtue (25)(排序)
- 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
- 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
- PAT_B_1015. 德才论 (25) or PAT_A_1062. Talent and Virtue (25)
- PAT 数据结构 08-排序3. Talent and Virtue (25)
- PAT(甲级)1062. Talent and Virtue (25)
- 【C++】PAT (advanced level)1062. Talent and Virtue (25)
- PAT-A 1062. Talent and Virtue (25)
- PAT 1062. Talent and Virtue (25) sort应用
- PAT 1062. Talent and Virtue (25)(判断是否是圣人君子小人)(代码超时)
- PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- 【PAT】【Advanced Level】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】1062. Talent and Virtue (25)
- PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- 1062. Talent and Virtue (25)