2013
11-27

# HDU 1084 What Is Your Grade?-模拟-[解题报告] C++

“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 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 the scores of N students in N lines for each case, and there is a blank line after each case.

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

100
90
90
95

100

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cstring>
using namespace std;

class student
{
public:
int solve;
int time;
int idx;
int score;
};

int div(int g)
{
if(g==1)
return 1;
else
return g/2;
}

int wastetime(string tar)
{
string a,b,c;
int an,bn,cn,res=0;
for (int i=0;i<=1;i++)
a+=tar[i];
for (int j=3;j<=4;j++)
b+=tar[j];
for (int k=6;k<=7;k++)
c+=tar[k];
an=atoi(a.c_str());
bn=atoi(b.c_str());
cn=atoi(c.c_str());

res=an*3600+bn*60+cn;
return res;
}

bool cmp(student c1,student c2)
{
if (c1.solve!=c2.solve)
return c1.solve>c2.solve;
else
return c1.time<c2.time;
}

bool cmp2(student c1,student c2)
{
return c1.idx<c2.idx;
}

int main()
{
student aclass[109];
int countstu[6];
int testcase;
while (cin>>testcase && testcase!=-1)
{
memset(countstu,0,sizeof(countstu));
string tar;
for (int i=0;i<testcase;i++)
{
cin>>aclass[i].solve>>tar;

aclass[i].time=wastetime(tar);
aclass[i].score=aclass[i].solve*10+50; //第一次处理 先给基础分
aclass[i].idx=i;
countstu[aclass[i].solve]++;
}

sort(aclass,aclass+testcase,cmp);

int pos=countstu[5];

for(int i=pos;i<pos+div(countstu[4]);i++) //一步一步的慢慢想，不要着急= =
{
aclass[i].score+=5;
}
pos+=countstu[4];
for(int i=pos;i<pos+div(countstu[3]);i++)
{
aclass[i].score+=5;

}
pos+=countstu[3];
for(int i=pos;i<pos+div(countstu[2]);i++)
{
aclass[i].score+=5;

}
pos+=countstu[2];
for(int i=pos;i<pos+div(countstu[1]);i++)
{
aclass[i].score+=5;

}
pos+=countstu[1];

sort(aclass,aclass+testcase,cmp2);  //处理再给排回去
for (int i=0;i<testcase;i++)
{
cout<<aclass[i].score<<endl;
}

cout<<endl;

}
return 0;
}

1. 5.1处，反了；“上一个操作符的优先级比操作符ch的优先级大，或栈是空的就入栈。”如代码所述，应为“上一个操作符的优先级比操作符ch的优先级小，或栈是空的就入栈。”

2. Thanks for using the time to examine this, I truly feel strongly about it and enjoy finding out far more on this subject matter. If achievable, as you achieve knowledge

3. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！