分值 : 25 难度 : 简单题 思路 : 结构体排序 坑点 : 有一个点,对于总分的取整,是对最后的总分取整,如果每次都取整去做会出错
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
#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 ; }}