• 1141 PAT Ranking of Institutions (25)


    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中的储存位置; 设计好比较函数,排序确定排名输出;
    注意点:排序,加上字符串就比较坑了;
    • string的输入输出为耗费大量时间,但是string的输入又不能用高效的scanf()所以string用cin输入输出,学生姓名,以及成绩都用scanf(),printf()输入输出。这样才能避免超时;
    • 总分的计算是: 先分别记录每一个级别的总分, 统计完之后再取加权和,否则最后一个测试点不能通过; 
    • 本来尝试用char*作为map的关键词,这样可以避免string的输入,奈何不会。 
     1 #include<iostream>
     2 #include<vector>
     3 #include<map>
     4 #include<string>
     5 #include<algorithm>
     6 using namespace std;
     7 struct Node{
     8   string sch;
     9   int grade, scorea, scoreb, scoret;
    10   int cnt;
    11   Node(){cnt=0; grade=0; scorea=0; scoreb=0; scoret=0;}
    12 };
    13 
    14 bool cmp(Node &a, Node &b){
    15   if(a.grade != b.grade) return a.grade > b.grade;
    16   if(a.cnt != b.cnt) return a.cnt < b.cnt;
    17   else return a.sch < b.sch;
    18 }
    19 void tolower(string& s){
    20   for(int i=0; i<s.size(); i++)
    21     if(s[i]>='A' && s[i]<='Z') s[i] += 32;
    22 }
    23 
    24 int main(){
    25   int n, i;
    26   scanf("%d", &n);
    27   map<string, int> idx;
    28   vector<Node> v(n+1);
    29   int index=0;
    30   for(i=0; i<n; i++){
    31     char name[10];
    32     int score, tempidx;
    33     string school;
    34     scanf("%s %d", name, &score);
    35     cin>>school;
    36     tolower(school);
    37     if(idx.find(school)==idx.end()){
    38       idx[school] = index;
    39       tempidx = index;
    40       v[tempidx].sch = school;
    41       index++;
    42     }else tempidx = idx[school];
    43     v[tempidx].cnt += 1;
    44     if(name[0]=='A') v[tempidx].scorea += score;
    45     else if(name[0] == 'B') v[tempidx].scoreb += score;
    46     else v[tempidx].scoret += score;
    47   }
    48   /*
    49     ScoreB/1.5 + ScoreA + ScoreT*1.5, 
    50     where ScoreX is the total score of the testees belong to this institution on level X;
    51     可知分别记录三种级别的总分数, 最后再加权求和,否则最后一个测试点会正确
    52   */
    53   for(i=0; i<index; i++) v[i].grade = (int)(v[i].scoret*1.5+v[i].scorea+v[i].scoreb/1.5);
    54   sort(v.begin(), v.begin()+index, cmp);
    55   int rank=1;
    56   printf("%d
    ", index);
    57   for(i=0; i<index; i++){
    58     if(i!=0 && v[i].grade!=v[i-1].grade) rank=i+1;
    59     printf("%d %s %d %d
    ", rank, v[i].sch.c_str(), v[i].grade, v[i].cnt);
    60   }
    61   return 0;
    62 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    spark internal
    74LS153 选择器 【数字电路】
    Linux(centos)下mysql编译安装教程
    Android画布更新过程OnDraw调用过程
    Android中使用ContentProvider进行跨进程方法调用
    hdu5414(2015多校10)--CRB and String(字符串匹配)
    徒弟们对话,遇到sb领导,离职吧
    【Cocos2d-x 017】 多分辨率适配全然解析
    编程精粹--编写高质量C语言代码(4):为子系统设防(一)
    为SSD编程(4)——高级功能和内部并行
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9164576.html
Copyright © 2020-2023  润新知