PAT 1141

题目 : PAT Ranking of Institutions

分值 : 25
难度 : 简单题
思路 : 结构体排序
坑点 : 有一个点,对于总分的取整,是对最后的总分取整,如果每次都取整去做会出错

具体代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
using namespace std ;
typedef struct Node
{
string name ;
double score= 0;
int count = 0 ;
int rank = 1 ;
}Nodes;
map <string , Node> data ;
map <string , Node> :: iterator itea ;
typedef pair<string , Node> PAIR ;
vector <PAIR> vc ;

string to_low(string s)
{
string t ;
for(int i = 0 ;i< s.size() ;i++)
t += tolower(s[i]) ;
return t ;
}
bool cmp(const PAIR&a , const PAIR &b)
{
int aa=a.second.score , bb=b.second.score;
if(aa!=bb)
return aa>bb ;
else if(a.second.count!= b.second.count)
return a.second.count < b.second.count ;
return a.second.name < b.second.name ;
}
int main() {
int N ;
cin >> N ;
for(int i = 0 ; i< N ; i++)
{
string s , s2;
double value ;
cin >> s >> value >> s2 ;
s2 = to_low(s2);
data[s2].name = s2 ;
data[s2].count++ ;
if(s[0]=='B')
value /= 1.5;
if(s[0]=='T')
value *=1.5 ;
data[s2].score += value ;
}
for(itea = data.begin() ;itea!=data.end(); itea++)
{
vc.push_back( make_pair(itea->first , itea->second)) ;
}
sort(vc.begin(),vc.end(),cmp);
cout << vc.size()<<endl ;
for(int i = 0 ; i< vc.size() ; i++)
{
if(i)
{
if((int)vc[i-1].second.score == (int)vc[i].second.score)
vc[i].second.rank = vc[i-1].second.rank ;
else
vc[i].second.rank = i+1 ;
}
cout << vc[i].second.rank <<" "<<vc[i].second.name<<" "<<(int)vc[i].second.score<<" "<<vc[i].second.count <<endl ;
}
}