PAT.Basic level. T.1004.成绩排名
来源:互联网 发布:mac能玩仙剑4吗 编辑:程序博客网 时间:2024/06/07 22:27
这道题的难度在于用结构体导入数据。
然后把分数取出来排序,一开始在纠结会不会超时… 但是事实证明并不会zzz。因为最后只要求一个最大和一个最小。 最后一个循环查找最大rank和最小rank对应的学生名字和课程信息就够了,一次通过很稳健。
#include<stdio.h>main(){int max(int a[], int len){ int i; int maxid = 0; for ( i=1; i<len; i++) { if ( a[i] > a[maxid]){ maxid = i; } } return maxid;} struct{ char name[12]; char id[12]; int scores; }stu[1000]; int rank[1000]; int n,i,z,min,max1; char zz[15]={0}; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%s%s%d",&stu[i].name,&stu[i].id,&stu[i].scores); } for(i=1;i<=n;i++){ rank[i]=stu[i].scores; } for ( i=n; i>0 ; i--) { int maxid = max(rank,i+1); //swap a[maxid], a[len-1] int t = rank[maxid]; rank[maxid] = rank[i]; rank[i] =t; } for(i=1;i<=n;i++){ if(rank[n]==stu[i].scores){ max1=i; } if(rank[1]==stu[i].scores){ min=i; } } printf("%s %s\n",stu[max1].name,stu[max1].id); printf("%s %s",stu[min].name,stu[min].id); return 0;}
0 0
- PAT.Basic level. T.1004.成绩排名
- PAT (Basic Level)1004. 成绩排名
- PAT Basic Level 1004. 成绩排名 (20)
- PAT (Basic Level) Practise-1004. 成绩排名 (20)
- PAT BASIC LEVEL 1004. 成绩排名 (20)
- PAT(basic level) 1004 成绩排名
- PAT(Basic Level)_1004_成绩排名
- 1004. 成绩排名(PAT Basic)
- PAT (Basic Level) Practise (中文)—— 1004. 成绩排名
- 【C++】浙大PAT (Basic Level)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- Pat(Basic Level)Practice--1004(成绩排名)
- 浙江大学PAT---Basic Level---1004----成绩排名
- Basic Level 1004. 成绩排名 (20)
- PAT basic level T.1001
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20) C语言
- PAT (Basic Level) Practise (中文)---1004 成绩排名 (20)
- 项脊轩志-2017年元宵节后
- Item31 Avoid default capture modes
- dubbo-spi扩展一
- Python安装lxml出错解决
- 【TerryHe 博客园】Spring Boot 应用示例
- PAT.Basic level. T.1004.成绩排名
- mysql Error:1052 Column 'xxx' in where clause is ambiguous
- Hibernate复习
- dubbo-spi扩展二
- windows环境下wampserver的配置教程
- jvm笔记04:类文件结构
- MySQL中实现upsert操作
- python特性(二):迭代器与for语句
- [Python入门及进阶笔记]Python-decorator装饰器小结