int main()
{
    using namespace std;
    string s;
    map<string, int> counters;
    
    while(cin >> s)
        ++counters[s];

    typedef map<int, vector<string> > Ranges;
    Ranges r;
    for(map<string, int>::const_iterator it = counters.begin();
        it != counters.end(); ++it) {
        r[it->second].push_back(it->first);
    }
    for(Ranges::const_iterator it = r.begin();
        it != r.end(); ++it) {
        cout << it->first << ":";
        for(vector<string>::const_iterator i = it->second.begin();
            i != it->second.end(); ++i) {
            cout << " " << *i;
        }
        cout << endl;
    }
    return 0;
}
示例#2
0
int main(int argc, char* argv[])
{
    using namespace std;
    StudentList students;
    read(std::cin, students);
   
    typedef map<string, vector<string> > Ranges;
    Ranges m;

    for(StudentList::const_iterator it = students.begin();
        it != students.end(); ++it) {
        m[grade_range(*it)].push_back(it->name);
        cout << it->name << " " << grade(*it) 
            << " " << grade_range(*it) << endl;
    }
    cout << string(10,'-') << endl;
    
    for(Ranges::const_iterator it = m.begin();
        it != m.end(); ++it) {
        const vector<string>& s = it->second;
        cout << it->first << "(" << s.size() << "):";
        for(vector<string>::const_iterator i = s.begin();
            i != s.end(); ++i)
            cout << " " << *i;
        cout << endl;
    }
    return 0;
}