• 1141 PAT Ranking of Institutions (25 分)


    水~。

    const int N=1e5+10;
    struct Node
    {
        int scoreb,scorea,scoret;
        int score;
        int cnt;
        int rank;
        string school;
        bool operator<(const Node &W) const
        {
            if(score != W.score) return score > W.score;
            if(cnt != W.cnt) return cnt < W.cnt;
            return school < W.school;
        }
    };
    map<string,Node> mp;
    int n;
    
    string trans(string s)
    {
        for(int i=0;i<s.size();i++)
            s[i]=tolower(s[i]);
        return s;
    }
    
    int main()
    {
        cin>>n;
    
        for(int i=0;i<n;i++)
        {
            string id,school;
            int score;
            cin>>id>>score>>school;
            school=trans(school);
            mp[school].school=school;
            if(id[0] == 'A')
                mp[school].scorea+=score;
            else if(id[0] == 'B')
                mp[school].scoreb+=score;
            else
                mp[school].scoret+=score;
            mp[school].cnt++;
        }
    
        vector<Node> res;
        for(auto t:mp)
        {
            t.se.score=t.se.scoreb/1.5+t.se.scorea+t.se.scoret*1.5;
            res.pb(t.se);
        }
    
        sort(res.begin(),res.end());
        cout<<res.size()<<endl;
        for(int i=0;i<res.size();i++)
        {
            if(i && res[i].score == res[i-1].score)
                res[i].rank=res[i-1].rank;
            else
                res[i].rank=i+1;
            cout<<res[i].rank<<' '<<res[i].school<<' '<<res[i].score<<' '<<res[i].cnt<<endl;
        }
    
        //system("pause");
        return 0;
    }
    
  • 相关阅读:
    栈的经典运用-求值数学表达式
    java中Stack的源码解析
    java-背包的实现
    数据库的事务的特性及隔离级别
    EnumMap的用法和源码解析
    java final关键字的解析
    java中的static关键字解析
    XPath如何定位dom节点
    java 枚举(enum) 详细用法
    jdk动态代理
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14481155.html
Copyright © 2020-2023  润新知