HDU-1084(结构体sort)

xiaoxiao2021-02-28  8

H - What Is Your Grade?   “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 易错点: you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems。即得到4分的前一半学生能得到95。以此类推。AC Code#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct Data { int p; char time[10]; int t; int grade; int id; }; bool cmp1(Data x, Data y) { if(x.p > y.p) return 1; else if(x.p == y.p) { return x.t < y.t; } else return 0; } bool cmp2(Data x, Data y) { return x.id < y.id; } int main() { int n; while(~scanf("%d",&n)) { if(n <= 0) break; Data st[n+1]; for(int i=1; i<=n; i++) { scanf("%d %s",&st[i].p,st[i].time); st[i].t = ((st[i].time[0]-'0')*10 + (st[i].time[1]-'0'))*3600 + ((st[i].time[3]-'0')*10 + (st[i].time[4]-'0'))*60 + ((st[i].time[6]-'0')*10 + (st[i].time[7]-'0')); st[i].id = i; } sort(st+1,st+1+n,cmp1); int a=0, b=0, c=0, d=0; for(int i=1; i<=n; i++) { if(st[i].p == 4) a++; if(st[i].p == 3) b++; if(st[i].p == 2) c++; if(st[i].p == 1) d++; } int x=0, y=0, z=0, m=0; for(int i=1; i<=n; i++) { if(st[i].p == 5) st[i].grade = 100; else if(st[i].p == 4) { if(x==0) { st[i].grade = 95; x++; } else if(x < (a/2)) { st[i].grade = 95; x++; } else { st[i].grade = 90; } } else if(st[i].p == 3) { if(y==0) { st[i].grade = 85; y++; } else if(y < (b/2)) { st[i].grade = 85; y++; } else { st[i].grade = 80; } } else if(st[i].p == 2) { if(z==0) { st[i].grade = 75; z++; } else if(z < (c/2)) { st[i].grade = 75; z++; } else { st[i].grade = 70; } } else if(st[i].p == 1) { if(m==0) { st[i].grade = 65; m++; } else if(m < (d/2)) { st[i].grade = 65; m++; } else { st[i].grade = 60; } } else st[i].grade = 50; } sort(st+1,st+1+n,cmp2); for(int i=1; i<=n; i++) { printf("%d\n",st[i].grade); } printf("\n"); } return 0; }              
转载请注明原文地址: https://www.6miu.com/read-2000141.html

最新回复(0)