1015. 德才论 (25)
来源:互联网 发布:俄罗斯杜马选举知乎 编辑:程序博客网 时间:2024/05/16 18:01
#include<stdio.h>#include<stdlib.h>#include<math.h> struct student{ int StuId; int moral; int talent; };int cmp(const void *a,const void *b){ struct student *s1 = (struct student *)a, *s2 = (struct student *)b; if( s1 -> moral+ s1->talent< s2->moral + s2->talent ) return 1; else if( s1->moral+s1->talent==s2->moral+s2->talent) { if( s1->moral<s2->moral ) return 1; else if( s1->moral==s2 ->moral) { if( s1->StuId>s2->StuId ) return 1; else return -1; } else return -1; } else return -1;}int main(){ int num , minGra , maxGra ; int count = 0 ; int i ; int flag1 = 0 ; int flag2 = 0 ; int flag3 = 0 ; int flag4= 0 ; scanf("%d %d %d",&num,&minGra,&maxGra); struct student stu[num]; struct student fir[num]; struct student sec[num]; struct student thi[num]; struct student fou[num]; for(i = 0 ; i < num ; ++i){ scanf("%d %d %d",&stu[i].StuId,&stu[i].moral,&stu[i].talent); } for(i = 0 ; i < num ; ++i){ if(stu[i].moral < minGra || stu[i].talent < minGra){ }else{ ++count; if(stu[i].moral >= maxGra && stu[i].talent >= maxGra){ fir[flag1++] = stu[i]; }else if(stu[i].moral >= maxGra && stu[i].talent < maxGra){ sec[flag2++] = stu[i]; }else if(stu[i].moral < maxGra && stu[i].talent < maxGra && stu[i].moral >= stu[i].talent ){ thi[flag3++] = stu[i]; }else{ fou[flag4++] = stu[i]; } } } printf("%d\n",count); qsort(fir , flag1 , sizeof(fir[0]) , cmp); for(i = 0 ; i < flag1 ; ++i){ printf("%d %d %d", fir[i].StuId , fir[i].moral, fir[i].talent); printf("\n"); } qsort(sec , flag2 , sizeof(sec[0]) , cmp ); for(i = 0 ; i < flag2 ; ++i){ printf("%d %d %d", sec[i].StuId , sec[i].moral, sec[i].talent); printf("\n"); } qsort(thi , flag3 , sizeof(thi[0]) , cmp); for(i = 0 ; i < flag3 ; ++i){ printf("%d %d %d", thi[i].StuId , thi[i].moral, thi[i].talent); printf("\n"); } qsort(fou , flag4 , sizeof(fou[0]) , cmp); for(i = 0 ; i < flag4 ; ++i){ printf("%d %d %d", fou[i].StuId , fou[i].moral, fou[i].talent); printf("\n"); } return 0;}
阅读全文
0 0
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- 1015. 德才论 (25)
- Spark性能优化指南——高级篇
- String 类------字符串转字符数组判断字符串中是否含有字母
- 前端学习(一)CSS基础
- JavaScript实现图片预览功能
- 程序员老司机总结的22个编程经验(转)
- 1015. 德才论 (25)
- JAVA发送http get/post请求、调用http接口、方法
- <java EE 项目 : MyForum (听说可以当毕业设计?)> 需求说明
- 轰炸问题、连续子序列的积、n个最大连续子序列和
- win7x64下mysql5.7.18解压版的安装
- Mac OS 下使用Eclipse + CDT 搭建C/C+ 开发环境
- 工作日记2017.07.05 简单操作es
- 1016. 部分A+B (15)
- springMVC前后台传值乱码问题