题目:
Problem Description “Point, point, life of student!” Come on! |
Input Input contains multiple test cases. Each test case |
Output Output the scores of N students in N lines for each |
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 |
比较简单的一道题目……首先根据耗时和解决题目的数量进行排序,然后根据题目要求进行分数换算,这里面if语句的顺序弄反了让我提交了好几次才ac...
最后再根据输入位置进行排序输出...
写的有点麻烦
#include "stdafx.h" #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; struct Student { int p; string s; int grade; int order; }; bool cmp(const Student&a,const Student&b) { if(a.p!=b.p) return a.p>b.p; else return a.s<b.s; } bool cmp2(const Student&a,const Student&b) { return a.order<b.order; } int main() { int n; while(scanf_s("%d",&n)&&n>0) { vector<Student> t; Student temp; int k=n; temp.p=100; t.push_back(temp); int j=0; int count[6]={0}; while(n--) { cin>>temp.p>>temp.s; temp.order=j++; t.push_back(temp); } sort(t.begin()+1,t.end(),cmp); //temp.p=100; //t.push_back(temp); for (int i = 1; i < k+1; i++) { count[t[i].p]++; } for (int i = 0; i < 6; i++) { count[i]==1?count[i]=-5:count[i]/=2; } for (int i = 1; i < k+1; i++) { if(count[t[i].p]==-5) t[i].grade=50+t[i].p*10+5; if (count[t[i].p]==0) { t[i].grade=50+t[i].p*10; } if(count[t[i].p]>0) { t[i].grade=50+t[i].p*10+5; count[t[i].p]--; } if(t[i].p==5||t[i].p==0) t[i].grade=50+t[i].p*10; } sort(t.begin()+1,t.end(),cmp2); for (int i = 1; i < k+1; i++) { cout<<t[i].grade<<endl; } cout<<endl; } return 0; }