题目链接:https://vjudge.net/contest/126708#problem/E
题意:给做出的题目个数,5个的100分,4个的前n/2的同学95,后n/2的90 后面一次类推,没做出来的全是50分 这个题只要模拟下就好了 先按题目个数拍好序 得到每个题目做出的人数,在打分,最后在按原来的顺序排序 ,在一次输出他们所得的分数;按原来的顺序排序可以先给每个要个变量记住他们的顺序,在排序就好
AC代码:
1 #include <iostream> 2 #include<algorithm> 3 #include <string> 4 using namespace std; 5 struct Student 6 { 7 int garde; 8 string time; 9 int shunxu; 10 int fenshu; 11 }; 12 bool cmp1(Student a,Student b) //按原顺序排序的比较函数 13 { 14 return a.shunxu<b.shunxu; 15 } 16 bool cmp(Student a,Student b) //按题目个数排序的比较函数 17 { 18 if(a.garde == b.garde) 19 { 20 return a.time < b.time; 21 } 22 else return a.garde < b.garde; 23 } 24 int main() 25 { 26 int t,t1,t2,t3,t4,l1,l2,l3,l4; 27 while(cin>>t) 28 { 29 if(t==-1) break; 30 Student a[101]; 31 t1 = 0; 32 t2= 0; 33 t3=0; 34 t4=0; 35 for(int i = 0; i < t; i ++) 36 { 37 cin>>a[i].garde>>a[i].time; 38 a[i].shunxu = i; 39 if(a[i].garde == 1) t1 ++; //统计各个题目的人数 40 if(a[i].garde == 2) t2 ++; 41 if(a[i].garde == 3) t3 ++; 42 if(a[i].garde == 4) t4 ++; 43 } 44 sort(a,a+t,cmp); 45 t1 = t1/2; 46 t2=t2/2; 47 t3=t3/2; 48 t4=t4/2; 49 l1=1; 50 l2=1; 51 l3=1; 52 l4=1; 53 for(int i =0; i < t; i++) //给每个按照打分制度同学打分 54 { 55 if(a[i].garde == 1) 56 { 57 if(l1<=t1) 58 { 59 a[i].fenshu = 65; 60 l1++; 61 } 62 else a[i].fenshu = 60; 63 } 64 if(a[i].garde == 2 ) 65 { 66 if(l2<=t2) 67 { 68 a[i].fenshu = 75; 69 l2++; 70 } 71 else a[i].fenshu = 70; 72 } 73 if(a[i].garde == 3 ) 74 { 75 if(l3<=t3) 76 { 77 a[i].fenshu = 85; 78 l3++; 79 } 80 else a[i].fenshu = 80; 81 } 82 if(a[i].garde == 4) 83 { 84 if(l4<=t4) 85 { 86 a[i].fenshu = 95; 87 l4++; 88 } 89 else a[i].fenshu = 90; 90 } 91 if(a[i].garde == 5) a[i].fenshu = 100; 92 if(a[i].garde == 0) a[i].fenshu = 50; 93 } 94 sort(a,a+t,cmp1); //按原序拍好序 在依次输出分数 95 for(int i = 0; i <t; i++) 96 cout<<a[i].fenshu<<endl; 97 cout<<endl; 98 } 99 return 0; 100 }