hdu 1084 What Is Your Grade?

努力总会有收获的,虽然一直在刷水题,但感觉代码的正确率越来越高了。坚持是最重要的,看到几个大神的博客,hdu,poj题目数量上百道,真心佩服,希望我也能坚持下来。

What Is Your Grade?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4032    Accepted Submission(s): 1198

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!
 
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
 
Author
lcy
 
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 struct Sa
 6 {
 7     int m;
 8     char t[20];
 9     int sum;
10     int p;
11 };
12 bool comp(struct Sa a,struct Sa b)
13 {
14     if(a.m!=b.m)
15       return a.m>b.m;  //答题数目降序
16     else if(strcmp(a.t,b.t)<0)
17       return true;
18       else return false;   
19 }
20 bool comp2(struct Sa a,struct Sa b)
21 {
22     if(a.p<b.p)
23     return true;
24     else return false;
25 }
26 int main()
27 {
28     int n;
29     while(~scanf("%d",&n)&&n!=-1)
30     {
31         struct Sa a[1000];
32         int i,num4=0,num3=0,num2=0,num1=0,num5=0;
33         for(i=0;i<n;i++)
34         {
35             scanf("%d",&a[i].m);
36             if(a[i].m==5)
37               a[i].sum=100;
38              if(a[i].m==0)
39               a[i].sum=50; 
40             scanf("%s",&a[i].t);
41             a[i].p=i;
42         }  
43         sort(a,a+n,comp);
44         for(i=0;i<n;i++)
45         {
46             if(a[i].m==5)
47               num5++;
48             if(a[i].m==4)
49               num4++;
50             if(a[i].m==3)
51               num3++;
52             if(a[i].m==2)
53               num2++;
54             if(a[i].m==1)
55               num1++;        
56         }
57         for(i=num5;i<num5+num4/2;i++)
58         {
59             a[i].sum=95;
60         }
61         for(i=num5+num4/2;i<num5+num4;i++)
62         {
63             a[i].sum=90;
64         }
65         for(i=num5+num4;i<num5+num4+num3/2;i++)
66         {
67             a[i].sum=85;
68         }
69         for(i=num5+num4+num3/2;i<num5+num4+num3;i++)
70         {
71             a[i].sum=80;
72         }
73         for(i=num5+num4+num3;i<num5+num4+num3+num2/2;i++)
74         {
75             a[i].sum=75;
76         }
77         for(i=num5+num4+num3+num2/2;i<num5+num4+num3+num2;i++)
78         {
79             a[i].sum=70;
80         }
81         for(i=num5+num4+num3+num2;i<num5+num4+num3+num2+num1/2;i++)
82         {
83             a[i].sum=65;
84         }
85         for(i=num5+num4+num3+num2+num1/2;i<num5+num4+num3+num2+num1;i++)
86         {
87             a[i].sum=60;
88         }
89         sort(a,a+n,comp2);
90         for(i=0;i<n;i++)
91         printf("%d
",a[i].sum);
92         printf("
");
93     }
94 }


代码看起来蛮恐怖的...囧...其实那堆num+什么的可以用个数组表示,在读入数据的时候就统计,用了两次sort(),对于这种需要排序后计算然后按原来顺序输出的情况,就在结构体中建一个标记专门用来存放原来的顺序,第一次排序被打乱后,再排一次序就回来了。strcmp()比较字符串大小非常好用。

原文地址:https://www.cnblogs.com/xurenwen/p/3866351.html