PAT Basic 1085 PAT units ranking (25 points)

After each PAT examination, the examination center will publish a unit of the candidates list. This question will ask you to realize this function.

Input formats:

The first input line is given a positive integer N ( ≤), i.e., the number of candidates. Then N rows, each row gives the information for a candidate in the following format:

准考证号 得分 学校

Which 准考证号is a string of six characters, the first letter indicates the level of the exam: Bon behalf of B, Aon behalf of Class A, Trepresents the top; 得分is [, 0100] integer in the range; 学校by no more than six English letters the unit code (case insensitive). Note: Title ensure that each candidate's ticket number is different.

Output formats:

First, the number of output units in a row. Then in the following format output unit of the non-descending list:

排名 学校 加权总分 考生人数

Wherein 排名a ranking of the units (from the beginning); 学校are all lowercase letters code output unit; 加权总分is defined as the 乙级总分/1.5 + 甲级总分 + 顶级总分*1.5integer part; 考生人数is the total number of units belonging to the examinee.

School weighted total score ranked first. If tied, should correspond to the same rank, according to the number of candidates in ascending output. If still tied, press lexicographical output unit code.

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


Always remember ordering accuracy problems, the last three points of precision, can be used toInt way to resolve this, the first strong into Int, then compared, due to the double data type, so you can turn back. You must go to a fraction
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct school{
    double grade=0.0;
    int coun=0;
};
void toInt(pair<string,school>& p1){
    int tmp=(int)p1.second.grade;
    p1.second.grade=(double)tmp;
}
bool cmp(const pair<string,school>& p1,const pair<string,school>& p2){
    if(p1.second.grade!=p2.second.grade) return p1.second.grade>p2.second.grade;
    else if(p1.second.coun!=p2.second.coun) return p1.second.coun<p2.second.coun;
    else return p1.first<p2.first;
}
int main()
{
    int n;
    unordered_map<string,school> m;
    cin>>n;
    string id,sch;double grade;
    while(n--){
        cin>>id>>grade>>sch;
        if(id[0]=='T') grade*=1.5;
        else if(id[0]=='A');
        else grade/=1.5;
        for(int i=0;i<sch.length();i++) sch[i]=tolower(sch[i]);
        m[sch].grade+=grade;
        m[sch].coun++;
    }
    vector<pair<string,school>> v(m.begin(),m.end());
    for_each(v.begin(),v.end(),toInt);
    sort(v.begin(),v.end(),cmp);
    int rank=1;
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++){
        if(i!=0&&v[i].second.grade!=v[i-1].second.grade) rank=(i+1);
        printf("%d %s %d %d\n",rank,v[i].first.c_str(),(int)v[i].second.grade,v[i].second.coun);
    }
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11618960.html