zoukankan      html  css  js  c++  java
  • poj 2153 Rank List(查找,Map)

    题目链接:http://poj.org/problem?id=2153

    思路分析:

    判断Li Ming的成绩排名,需要在所有的数据章查找成绩比其高的人的数目,为查找问题。

    查找问题可以使用Hash表,STL中的Map,查找树,或者使用排序与二分查找即可。

    代码:

    #include <iostream>
    #include <map>
    #include <string>
    using namespace std;
    
    int main()
    {
        int personNum, examTimes, scoreOfLi;
        string stuName;
        map<string, int> rankList;
    
        cin >> personNum;
        cin.get( );
        for (int i = 0; i < personNum; ++i)
        {
            getline(cin, stuName);
            rankList[stuName] = 0;
        }
        cin >> examTimes;
        cin.get( );
        for (int i = 0; i < examTimes; ++ i)
        {
            int score;
    
            for (int j = 0; j < personNum; ++ j)
            {
                cin >> score;
                cin.get( );
                getline(cin, stuName);
                rankList[stuName] += score;
                if (stuName == string("Li Ming"))
                    scoreOfLi = rankList[stuName];
            }
    
            int rankOfLiMing = 1;
            for (map<string, int>::iterator iter = rankList.begin( ); iter != rankList.end(); ++iter)
            {
                if (iter->second > scoreOfLi)
                    rankOfLiMing++;
            }
            cout << rankOfLiMing << endl;
        }
    
        return 0;
    }
  • 相关阅读:
    3-2
    3-1
    2-11
    2-10
    2-7
    2-9
    springboot 使用undertow代替tomcat容器提高吞吐量
    springboot—JVM性能参数调优
    springbootDay3
    springboot_Mybaits_PageHelper
  • 原文地址:https://www.cnblogs.com/tallisHe/p/4264035.html
Copyright © 2011-2022 走看看