HDU 1084 - ACM

题目不难,但是需要对数据进行处理,我的代码有些冗长,希望以后能改进。。。

主要思路是先算总的时间,然后进行对比,将做同样题数的前一半的人筛选出来。

/状态:AC/

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!       
              

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.       
              

Output

Output the scores of N students in N lines for each case, and there is a blank line after each case.       
              

Sample Input

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

Sample Output

100 90 90 95
 
100
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int M(int i,char T[1005][10])
{
int n;
n=(T[i][2]-'0')*36000+(T[i][3]-'0')*3600+(T[i][5]-'0')*600+(T[i][6]-'0')*60+(T[i][8]-'0')*10+(T[i][9]-'0');
return n;
} int main()
{
//freopen("1.txt","r",stdin);
//freopen("2.txt","w",stdout);
char T[1005][10]={0};
long long score[6][1005]={0};
int c;
while(cin>>c&&c!=-1)
{
getchar();
int j=0;
int a0=0,a1=0,a2=0,a3=0,a4=0;
for(int i=0;i<c;i++){
for(int m=0;m<10;m++)
cin.get(T[i][m]);
getchar();
}
for(int i=0;i<c;i++)
{
if(T[i][0]=='4')
{
score[4][a4++]=M(i,T);
}
if(T[i][0]=='3')
{
score[3][a3++]=M(i,T);
}
if(T[i][0]=='2')
{
score[2][a2++]=M(i,T);
}
if(T[i][0]=='1')
{
score[1][a1++]=M(i,T);
}
}
sort(score[1],score[1]+a1);
sort(score[2],score[2]+a2);
sort(score[3],score[3]+a3);
sort(score[4],score[4]+a4);
for(int i=0;i<c;i++)
{
if(T[i][0]=='4')
{
if(a4==1) {cout<<"95"<<endl; continue;}
for(int k=0;k<a4;k++)
{
if(score[4][k]==M(i,T))
{
if(k<a4/2) {cout<<"95"<<endl; break;}
else {cout<<"90"<<endl; break;}
}
}
}
if(T[i][0]=='3')
{
if(a3==1) {cout<<"85"<<endl; continue;}
for(int k=0;k<a3;k++)
{
if(score[3][k]==M(i,T))
{
if(k<a3/2) {cout<<"85"<<endl; break;}
else {cout<<"80"<<endl; break;}
}
}
}
if(T[i][0]=='2')
{
if(a2==1) {cout<<"75"<<endl; continue;}
for(int k=0;k<a2;k++)
{
if(score[2][k]==M(i,T))
{
if(k<a2/2) {cout<<"75"<<endl; break;}
else {cout<<"70"<<endl; break;}
}
}
}
if(T[i][0]=='1')
{
if(a1==1) {cout<<"65"<<endl; continue;}
for(int k=0;k<a1;k++)
{
if(score[1][k]==M(i,T))
{
if(k<a1/2) {cout<<"65"<<endl; break;}
else {cout<<"60"<<endl; break;}
}
}
}
if(T[i][0]=='5')
{
cout<<"100"<<endl; continue;
}
if(T[i][0]=='0')
{
cout<<"50"<<endl; continue;
}
}
cout<<endl;
}
return 0;
}
 
 
 
上一篇:按Enter键执行表单验证


下一篇:js之yeild