hdoj1084What Is Your Grade?(sort+结构体)
来源:互联网 发布:礼物淘宝知乎 编辑:程序博客网 时间:2024/06/03 13:45
Problem Description
“Point, point, life of student!”
This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course.
There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50.
Note, only 1 student will get the score 95 when 3 students have solved 4 problems.
I wish you all can pass the exam!
Come on!
This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course.
There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50.
Note, only 1 student will get the score 95 when 3 students have solved 4 problems.
I wish you all can pass the exam!
Come on!
Input
Input contains multiple test cases. Each test case contains an integer N (1<=N<=100, the number of students) in a line first, and then N lines follow. Each line contains P (0<=P<=5 number of problems that have been solved) and T(consumed time). You can assume that all data are different when 0<p.
A test case starting with a negative integer terminates the input and this test case should not to be processed.
A test case starting with a negative integer terminates the input and this test case should not to be processed.
Output
Output the scores of N students in N lines for each case, and there is a blank line after each case.
Sample Input
45 06:30:174 07:31:274 08:12:124 05:23:1315 06:30:17-1
Sample Output
100909095100
Author
lcy
题意:输入一个整数,代表人数,后面每一行是考生信息,分别是该考生完成的题目数目以及所用的时间。在答完n到题目的考试中,只有排名前二分之一才能得到较多的分数(95,85,75,65)。
用两个sort函数,第一个用来按答出题目多少来排序,如果所答的题目数量一样,则按他们所消耗的时间排序。第二个sort用来恢复输入时考生的顺序。最后逐次输出成绩。
代码如下:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct student{int m;char time[110];int point;int l;}arr[110];bool cmp1(student a,student b){if(a.m==b.m){return strcmp(a.time,b.time)<0;}elsereturn a.m>b.m;} bool cmp2(student a,student b){return a.l<b.l;}int main(){int n,i,t;while(scanf("%d",&n)!=EOF){int x=0,y=0,z=0,l=0;if(n<0)break;for(i=0;i<n;i++){scanf("%d %s",&arr[i].m,arr[i].time);arr[i].l=i;if(arr[i].m==4)x++;if(arr[i].m==3)y++;if(arr[i].m==2)z++;if(arr[i].m==1)l++;}sort(arr,arr+n,cmp1);int flag=1,ant=1,ans=1,anx=1;for(i=0;i<n;i++){if(arr[i].m==5)arr[i].point=100;if(arr[i].m==4&&flag<=x/2){arr[i].point=95;flag++;}else if(arr[i].m==4&&flag>x/2)arr[i].point=90;if(arr[i].m==3&&ant<=y/2){ant++;arr[i].point=85;}else if(arr[i].m==3&&ant>y/2)arr[i].point=80;if(arr[i].m==2&&ans<=z/2){ans++; arr[i].point=75;}else if(arr[i].m==2&&ans>z/2)arr[i].point=70;if(arr[i].m==1&&anx<=l/2){anx++;arr[i].point=65;}else if(arr[i].m==1&&anx>l/2)arr[i].point=60;if(arr[i].m==0){arr[i].point=50;}}sort(arr,arr+n,cmp2);for(i=0;i<n;i++){printf("%d\n",arr[i].point);}printf("\n");}}
0 0
- hdoj1084What Is Your Grade?(结构体+sort)
- hdoj1084What Is Your Grade?(sort+结构体)
- What Is Your Grade?(结构体+(sort))
- What Is Your Grade?(结构体+(sort))hd 1084
- HDU 问题1084 What Is Your Grade?(结构体+sort)
- hdoj 1084 What Is Your Grade?(sort函数按规则排序结构体数组)
- What Is Your Grade? (sort)
- hdu1084 What Is Your Grade? 结构体的应用
- hdoj 1872 What Is Your Grade? 【结构体排序】
- 【结构体排序】HDU1084 What Is Your Grade?
- 【杭电-oj】-1084-What Is Your Grade?(结构体)
- What Is Your Grade?(1084)
- What Is Your Grade?
- What Is Your Grade?
- What Is Your Grade?
- what is your grade
- What Is Your Grade?
- What Is Your Grade?
- 实现jQuery底层链式编程(二)
- 张宴的博客nginx+php+mysql搭建篇
- 游标
- 一个java数学题,给定一个数组,除了一个数出现1次之外,其余数都出现3次,输出出现一次的那个数。
- Rhythm韵:自制音乐app(1f)
- hdoj1084What Is Your Grade?(sort+结构体)
- hdu 5726 (线段树 GCD RMQ)多校第一场1004
- usb-c接口与USB接口的区别
- 五大常用算法之四:回溯法
- Android系统分享
- Scrapy框架结合Spynner采集需进行js,ajax动态加载的网页并提取网页信息(以采集微信公众号文章列表为例)
- 反射类的学习
- Android zygote
- Maven项目使用Jetty启动之后发生如下错误: