http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=1361
题意:
大BOSS列出他周游列国的各种情人,要求统计一下各个国家的人数,升序排列。
解题:
又偷懒上网找答案,学会了用map;map直接统计,而且直接是升序哦~方便强大
#include <iostream>
#include <map>
#include <string>
#include <stdio.h>
using namespace std;
// #define LOCAL_TEST
int main()
{
#ifdef LOCAL_TEST
freopen("f:\\in.txt", "r", stdin);
freopen("f:\\out.txt", "w+", stdout);
#endif
int nCase;
map <string, int> mList;
string str;
cin >>nCase;
cin.ignore();
for ( int i=0; i<nCase; i++ )
{
getline(cin, str, ' ');
if ( mList.count(str) )
mList[str]++;
else
mList[str] = 1;
getline(cin, str, '\n');
} // end for
for ( map <string, int>::iterator it = mList.begin(); it != mList.end(); it++ )
cout <<it->first <<' ' <<it->second <<'\n';
return 0;
}