1085 PAT unit ranking (25 point(s))
After each PAT, the exam center will issue a list of candidate units.This topic asks you to do this.
Input format:
Enter the first line to give a positive integer N (< 10 5), which is the number of candidates.Then N rows, each with one candidate's information in the following format:
Admission Number Scoring School
The passport number is a string of six characters, the first letter of which indicates the level of the test: B for Level B, A for Level A, T for Top Level, the score is an integer in the [0, 100] range, and the school is a unit code consisting of no more than six letters in English (case independent).Note: The Title guarantees that each examinee's admission number is different.
Output format:
First output the number of units in a row.The rankings of output units are then non-descending in the following format:
Number of school-weighted total score candidates ranked
The ranking is the ranking of the unit (starting from 1); the school is the unit code output in all lowercase letters; the weighted total score is defined as the integral part of the total score of Grade B/1.5+Total score of Grade A+Total top score*1.5; and the number of candidates is the total number of candidates belonging to the unit.
Schools are first ranked by weighted total.If they are side by side, they should have the same ranking and be output in ascending order according to the number of candidates.If they are still side-by-side, they are output in unit code dictionary order.
Input sample:
10 A57908 85 Au B57908 54 LanX A37487 60 au T28374 67 CMU T32486 24 hypu A66734 92 cmu B76378 71 AU A47780 45 lanx A72809 100 pku A03274 45 hypu
Output sample:
5 1 cmu 192 2 1 au 192 3 3 pku 100 1 4 hypu 81 2 4 lanx 81 2
Analysis:
Run did not pass completely, the last two case s timed out
Detailed code:
#include <iostream> #include <stdio.h> #include <string> #include <vector> #include <algorithm> using namespace std; typedef struct{ string university; int score; int total; }stu; int cmp(stu a,stu b){ if(a.score!=b.score){ return a.score>b.score; }else if(a.total!=b.total){ return a.total<b.total; }else{ return a.university[0]<b.university[0]; } } // 1085 PAT unit rank (25 point(s)) run timeout did not pass completely int main(void){ int n; cin>>n; vector<stu> s; for(int i=0;i<n;++i){ string admission,university; int score=0; cin>>admission>>score>>university; //scanf("%s %d %s",admission,&score,university); if(admission[0]=='B'){ score = (int)(score/1.5); }else if(admission[0]=='T'){ score = (int)(score*1.5); } for(int j=0;j<university.length();++j){ // To lower case if(university[j]>='A' && university[j]<='Z'){ university[j] += 32; } } int flag = 0; for(int j=0;j<s.size();++j){ if(s[j].university == university){ flag = 1; s[j].score += score; s[j].total += 1; break; } } if(flag==0){ stu t; t.score = score; t.university = university; t.total = 1; s.push_back(t); } } sort(s.begin(),s.end(),cmp); cout<<s.size()<<endl; int num = 1; for(int i=0;i<s.size();++i){ if(i>0 && s[i-1].score!=s[i].score){ num = i+1; } cout<<num<<" "<<s[i].university<<" "<<s[i].score<<" "<<s[i].total<<endl; } return 0; }// jinzheng 2018.7.22 14:13