标签:bool eve last student input ica sha hal integer
After each PAT, the PAT Center will announce the ranking of institutions based on their students‘ performances. Now you are asked to generate the ranklist.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<=10^5^), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where "ID" is a string of 6 characters with the first one representing the test level: "B" stands for the basic level, "A" the advanced level and "T" the top level; "Score" is an integer in [0, 100]; and "School" is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that "ID" is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where "Rank" is the rank (start from 1) of the institution; "School" is the institution code (all in lower case); "TWS" is the total weighted score which is defined to be the integer part of "Score~B~/1.5 + Score~A~ + Score~T~*1.5", where "Score~X~" is the total score of the testees belong to this institution on level X; and "Ns" is the total number of testees who belong to this institution.
The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.
Sample Input:
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
Sample Output:
5 1 cmu 192 2 1 au 192 3 3 pku 100 1 4 hypu 81 2 4 lanx 81 2
pat里面恶心人的大概就是排序了吧, pat的点真是奇怪呢!
题目大意:给出考生的姓名, 分数,学校,对每个学校按照总分排序, 分数相同的按照参加人数排序, 还是相同,则按照学校名字排序,学校名字同意转换为小写;
思路:用vector<node> v保存学校的参考人数, 总分; 用map<string, int>来保存每一个学校在v中的储存位置; 设计好比较函数,排序确定排名输出;
注意点:排序,加上字符串就比较坑了;
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<string> 5 #include<map> 6 using namespace std; 7 class node{ 8 public: 9 string id; 10 int ns; 11 double total; 12 node(){total=0.0; ns=0;} 13 }; 14 15 void convert(string &s){ 16 for(int i=0; i<s.size(); i++) 17 if(s[i]<=‘Z‘&&s[i]>=‘A‘) s[i] += 32; 18 } 19 bool cmp(node a, node b){ 20 int x=(int)a.total, y=(int)b.total; 21 if(x!=y) return x>y; 22 if(a.ns!=b.ns) return a.ns<b.ns; 23 return a.id<b.id; 24 } 25 26 int main(){ 27 int n, i; 28 cin>>n; 29 map<string, int> mmap; 30 vector<node> v(n); 31 int cnt=0; 32 for(i=0; i<n; i++){ 33 string sch; 34 char name[8]; 35 int index; 36 int s; 37 scanf("%s %d", name, &s); cin>>sch; 38 convert(sch); 39 double score=s*1.0; 40 if(name[0]==‘A‘) score *= 1.0; 41 else if(name[0]==‘B‘) score/=1.5; 42 else score *= 1.5; 44 if(mmap.count(sch)==0) mmap[sch]=cnt++; 45 index=mmap[sch]; 46 v[index].ns++; v[index].id=sch; v[index].total += score; 47 } 48 sort(v.begin(), v.begin()+cnt, cmp); 49 cout<<cnt<<endl; 50 int rank=1, last=(int)v[0].total; 51 for(i=0; i<cnt; i++){ 52 int now=(int)v[i].total; 53 if(i==0) printf("1 "); 54 else{ 55 if(now==last) printf("%d ", rank); 56 else{printf("%d ", i+1); rank=i+1; last=(int)v[i].total;} 57 } 58 cout<<v[i].id; 59 printf(" %d %d\n", now, v[i].ns); 60 } 61 return 0; 62 }
1141 PAT Ranking of Institutions (25)
标签:bool eve last student input ica sha hal integer
原文地址:https://www.cnblogs.com/mr-stn/p/9164576.html