PAT 1012 排序
来源:互联网 发布:秒赞网哪一个源码好 编辑:程序博客网 时间:2024/06/04 11:23
只会用这么蠢的方法,开辟了一堆空间。
还最高排名,,这些学生真虚伪。
好吧,想了一下,这代码更蠢了,除了其他人说的 1 1 2 3应该是1 1 3 4外;还有,
96 98 88
96 97! 88
96! 95 88!
带感叹号的是一个人的成绩,应该输出第一名,而我输出了第二名;
正确做法应该是:先把该同学各科成绩排名算出来,把最靠前的存起来在输出。懒得改了。
#include<cstdio>#include<string>#include<algorithm>using namespace std;int N,M;struct node{ int ID,C,M,E,A;}stu[2005],stuc[2005],stum[2005],stue[2005];bool cmp(node a,node b){return a.A>b.A;}bool cmpc(node a,node b){return a.C>b.C;}bool cmpm(node a,node b){return a.M>b.M;}bool cmpe(node a,node b){return a.E>b.E;}int main() {scanf("%d%d",&N,&M);for(int i=0;i<N;i++){ scanf("%d%d%d%d",&stu[i].ID,&stu[i].C,&stu[i].M,&stu[i].E); stu[i].A=(stu[i].C+stu[i].M+stu[i].E)/3+0.5; //先算完再类型转换}sort(stu,stu+N,cmpc);for(int i=0;i<N;i++) stuc[i]=stu[i]; sort(stu,stu+N,cmpm); for(int i=0;i<N;i++){ stum[i]=stu[i]; //printf("%d %d %d %d\n",stum[i].ID,stum[i].C,stum[i].M,stum[i].E); } sort(stu,stu+N,cmpe); for(int i=0;i<N;i++) stue[i]=stu[i]; sort(stu,stu+N,cmp);int id,cnt;for(int i=0;i<M;i++){ scanf("%d",&id); cnt=0; for(int j=0;j<N;j++){ if(id==stu[j].ID){ while(stu[j].A==stu[j-1].A)j--; printf("%d A\n",j+1); cnt=1; break; } else if(id==stuc[j].ID){ while(stuc[j].C==stuc[j-1].C)j--; printf("%d C\n",j+1); cnt=1; break; } else if(id==stum[j].ID){ while(stum[j].M==stum[j-1].M)j--; printf("%d M\n",j+1); cnt=1; break; } else if(id==stue[j].ID){ while(stue[j].E==stue[j-1].E)j--; printf("%d E\n",j+1); cnt=1; break; } } if(cnt==0) printf("N/A\n");}return 0;}
阅读全文
0 0
- PAT 1012 排序
- [排序]PAT1025 PAT Ranking
- PAT 1045 快速排序
- pat 1045. 快速排序
- PAT 1045.快速排序
- 文字处理&排序-PAT.A1016
- PAT-B1045. 快速排序
- PAT B1045. 快速排序
- PAT排序题总结
- PAT-A1075. PAT Judge (25)(排序)
- PAT 1025 PAT Ranking(双重排序)
- PAT 1025. PAT Ranking (25) 数据结构,排序
- 10-排序5 PAT Judge
- 10-排序5 PAT Judge
- 【PAT】1045. 快速排序(25)
- PAT-B 1045. 快速排序
- PAT-B 1045. 快速排序
- [PAT-乙级]1045.快速排序
- 【s5p4418嵌入式学习】u-boot学习之makefile注释07
- Ubuntu使用vim编辑器时方向键乱码和退格键不能使用的问题
- 小型HTTP服务器
- sql语句实现查询
- LeetCode.62
- PAT 1012 排序
- java中System.exit()方法
- [LeetCode] 3. Longest Substring Without Repeating Characters
- Android Studio AIDL实现
- jpg读取exif属性值
- more effective C++条款六解析
- git log的简化及美化
- web启动spring过程
- vimの可视模式