PAT 1055. The World's Richest
2014-03-06 22:33
106 查看
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1055
题解:
枚举查找符合条件的输出即可。
代码:
来源:/article/8560012.html
题解:
枚举查找符合条件的输出即可。
代码:
#include<cstdio> #include<cstring> #include<cmath> #include<string> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> using namespace std; #define INF 0x6fffffff struct person { char name[10];//姓名 int age;//年龄 int netWorth;//净资产 }richer[100005]; int q[100005]; int ageRank[205]; bool cmp(const struct person &a,const struct person &b) {//按 净资产 年龄 姓名 排序 if(a.netWorth!=b.netWorth) return a.netWorth>b.netWorth; else if(a.age!=b.age) return a.age<b.age; else return strcmp(a.name,b.name)<0; } int main() { int n,m,k,aMin,aMax; int idx=0,num,age; memset(ageRank,0,sizeof(ageRank)); scanf("%d%d",&n,&k); for(int i=0;i<n;++i) scanf("%s%d%d",richer[i].name,&richer[i].age,&richer[i].netWorth); sort(richer,richer+n,cmp); for(int i=0;i<n;++i) { ++ageRank[richer[i].age]; if(ageRank[richer[i].age]<101)//去除年龄大于100的 q[idx++]=i; } for(int i=1;i<=k;++i) { scanf("%d%d%d",&m,&aMin,&aMax); printf("Case #%d:\n",i); num=0; for(int j=0;j<idx&&num<m;++j) { age=richer[q[j]].age; if(aMin<=age&&age<=aMax) { printf("%s %d %d\n",richer[q[j]].name,richer[q[j]].age,richer[q[j]].netWorth); ++num; } } if(num==0) printf("None\n"); } return 0; }
来源:/article/8560012.html
相关文章推荐
- PAT-B 1055. 集体照
- PAT-1055. The World's Richest (25)
- [PAT-乙级]1055.集体照
- PAT 1055. The World's Richest (25)(净资产排序,然后按照年纪分类输出m个)
- pat 1055 The World's Richest
- PAT (Advanced) 1055. The World's Richest (25)
- [PAT乙级]1055. 集体照 (25)
- PAT甲级1055
- pat 1055. 集体照
- C++ - PAT - 1055. 集体照 (25)
- 浙江大学PAT_甲级_1055. The World's Richest (25)
- PAT--1055. The World's Richest
- PAT 1055. The World's Richest
- PAT basic 1055
- PAT 1055
- PAT考试乙级1055(C++语言实现) (重点题目)(思路)
- PAT 1055 Mooncake (25)(贪心,最大利润)(待修改)(官网有个测试点通不过,不知到错在哪,下次再改好了)
- pat 1055 区间前k个
- PAT(甲级)1055
- PAT(甲级)1055. The World's Richest (25)