zoukankan      html  css  js  c++  java
  • PAT 甲级 1141 PAT Ranking of Institutions (25 分)

    思路:

    1.以校名为索引存储相关信息;
    2.定义符合题意的sort()排序;

    代码:

    #include<iostream>
    #include<unordered_map>
    #include<string>
    #include<cctype>
    #include<vector>
    #include<algorithm>
    using namespace std;
    struct ins{
    	string code;
    	int tws,score[3]={0},ns;
    };
    bool cmp(const ins & a,const ins & b){
    	return a.tws==b.tws?(a.ns==b.ns?a.code<b.code:a.ns<b.ns):a.tws>b.tws;
    }
    int main(){
    	int n;
    	cin>>n;
    	unordered_map<string,ins> mp;
    	for(int i=0;i<n;i++){
    		string id,code;
    		int score;
    		cin>>id>>score>>code;
    		for(int j=0;j<code.length();j++) code[j]=tolower(code[j]);
    		mp[code].ns++;
    		id[0]=='B'||id[0]=='A'?mp[code].score['B'-id[0]]+=score:mp[code].score[2]+=score;
    	}
    	vector<ins> v;
    	for(auto e:mp)
    	{
    		ins i;
    		i.code=e.first;
    		i.tws=e.second.score[0]/1.5+e.second.score[1]+e.second.score[2]*1.5;
    		i.ns=e.second.ns;
    		v.push_back(i);
    	}
    	sort(v.begin(),v.end(),cmp);
    	int rank=1,size=v.size();
    	printf("%d
    ",size);
    	for(int i=0;i<size;i++)
    		if(i==0||v[i].tws==v[i-1].tws) printf("%d %s %d %d
    ",rank,v[i].code.c_str(),v[i].tws,v[i].ns);
    		else{
    			printf("%d %s %d %d
    ",i+1,v[i].code.c_str(),v[i].tws,v[i].ns);
    			rank=i+1;
    		}
    	return 0;
    }
    
  • 相关阅读:
    二分图最大匹配
    Problems about trees
    Hackerrank Going to the Office
    多校题解
    HDU #2966 In case of failure
    K-D Tree
    UOJ #10 pyx的难题
    bzoj 1090 字符串折叠
    uva 1347 旅行
    bzoj 1059 矩阵游戏
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12309092.html
Copyright © 2011-2022 走看看