본문 바로가기
개발/코딩

해커랭크(HackerRank) - Climbing the Leaderboard / C++

by lucidmaj7 2020. 6. 29.
728x90
반응형

문제 : 해커랭크  - Climbing the Leaderboard

난이도: midium

언어 : C++

https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem

 

Climbing the Leaderboard | HackerRank

Help Alice track her progress toward the top of the leaderboard!

www.hackerrank.com

 

// Complete the climbingLeaderboard function below.
vector<int> climbingLeaderboard(vector<int> scores, vector<int> alice) {
    vector<int> aliceRank ;
    set<int> scoreSet;
    for(auto iter = scores.begin();iter!=scores.end(); iter++)
    {
        scoreSet.insert(*iter);
    }
    int rank = 1;
    int idx = 1;
    int prevScore = *(scoreSet.rbegin());
    auto iter2 = ++(scoreSet.rbegin());
    
    for(auto iter  = alice.rbegin();iter!=alice.rend();iter++)
    {   
        int aliceScore = *iter;
        rank = idx;
        for(; iter2 != scoreSet.rend();iter2++)
        {
           
            if(prevScore<=aliceScore)
            {
                break;
            }
         
            prevScore = *iter2;
            rank++;
            idx++;
        }
        if(prevScore > aliceScore )
            rank++;
   
        aliceRank.push_back(rank);
    }
    reverse(aliceRank.begin(),aliceRank.end());

    return aliceRank;

}

728x90
반응형

댓글