您的位置:首页 > 其它

hdoj 1872 What Is Your Grade? 【结构体排序】

2016-07-19 21:44 309 查看

What Is Your Grade?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 10720    Accepted Submission(s): 3322


[align=left]Problem Description[/align]
“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!

 

[align=left]Input[/align]
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.

 

[align=left]Output[/align]
Output the scores of N students in N lines for each case, and there is a blank line after each case.

 

[align=left]Sample Input[/align]

4
5 06:30:17
4 07:31:27
4 08:12:12
4 05:23:13
1
5 06:30:17
-1

 

[align=left]Sample Output[/align]

100
90
90
95

100

 
时间化成秒,按正确题数打分即可

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node
{
int num;//添加编号以便记录
int p;
int h,m,s;
int t;
int score;
}stu[110];
int cmp1(Node a,Node b)//对总时间从小到大排序
{
return a.t<b.t;
}
int cmp2(Node a,Node b)//对编号从小到大排序
{
return a.num < b.num;
}
int main()
{
int n,i,j,k,s[10];//s[10]记录做对相同题目数的人数
while(scanf("%d",&n)!=EOF)
{
memset(s,0,sizeof(s));
if(n==-1)
return 0;
for(i=1;i<=n;i++)
{
scanf("%d %d:%d:%d",&stu[i].p ,&stu[i].h ,&stu[i].m ,&stu[i].s);
stu[i].num=i;
stu[i].t=stu[i].h*3600+stu[i].m*60+stu[i].s;
//现算整10的分数
if(stu[i].p==5)
{
stu[i].score=100;
continue;
}
if(stu[i].p==4)
{
stu[i].score=90;
s[4]++;
continue;
}
if(stu[i].p==3)
{
stu[i].score=80;
s[3]++;
continue;
}
if(stu[i].p==2)
{
stu[i].score=70;
s[2]++;
continue;
}
if(stu[i].p==1)
{
stu[i].score=60;
s[1]++;
continue;
}
if(stu[i].p==0)
{
stu[i].score=50;
continue;
}
}
sort(stu+1,stu+n+1,cmp1);	//先对时间排序,计算相同题目前50%名加上5分的情况
for(i=1;i<5;i++)
{
if(s[i]>=2)
{
int m=0;
for(k=1;k<=n;k++)
{
if((m<s[i]/2)&&(stu[k].p==i))
{
m++;
stu[k].score+=5;
}

}
}
}
sort(stu+1,stu+n+1,cmp2);//在对编号排序,按原输入顺序输出
for(i=1;i<=n;i++)
printf("%d\n",stu[i].score);
if(n)
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: