본문 바로가기
개발/코딩

해커랭크(HackerRank) - The Full Counting Sort / C++

by lucidmaj7 2020. 7. 11.
728x90
반응형

문제: 해커랭크 - The Full Counting Sort

언어 : C++

난이도: Midium

https://www.hackerrank.com/challenges/countingsort4/problem?h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen

 

The Full Counting Sort | HackerRank

The real counting sort.

www.hackerrank.com

 

// Complete the countSort function below.
void countSort(vector<vector<string>> arr) {
    map<int, vector<string>> strmap;
    int half =  arr.size()/2;
    for(int i = 0 ; i< arr.size() ;i++)
    {
        strmap[ atoi(arr[i][0].c_str()) ].push_back( half>i ? "-": arr[i][1]);
    }
    for(auto iter= strmap.begin();iter!=strmap.end();iter++)
    {
      
        for(int i = 0;i<iter->second.size();i++)
        {
            cout<<iter->second[i]<< " ";
        }
    }
}

728x90
반응형

댓글