map 값별 정렬

1271 단어
/*  PE7.1--      (  )
 *     7.2     ,               ,
 *      ,                  ,  
 *             
 *    :2013-1-6 15:51:25
 */
#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string s;
    map<string, int> counters;  //               

    cout << "      " << endl;
    //     ,          
    while (cin >> s)
    {
        ++counters[s];
    }

    map<int, vector<string> > counters1;
    for (map<string, int>::const_iterator it = counters.begin();
         it != counters.end(); ++it)
    {   // map -     
        counters1[it->second].push_back(it->first);
    }

    cout << "          :" << endl;

    //          
    for (map<int, vector<string> >::const_iterator it = counters1.begin();
         it != counters1.end(); ++it)
    {
        vector<string> vec_str = it->second;
        for (vector<string>::const_iterator vec_it = vec_str.begin();
             vec_it != vec_str.end(); ++vec_it)
        {
            cout << *vec_it << "\t" << it->first << endl;
        }

    }

    return 0;
}

좋은 웹페이지 즐겨찾기