题意:
输入一组字符串, 每行的第一个单词表示国家名, 统计各个国家名出现次数, 然后按国家名的字母序由小到大进行输出. 思路:
<国家名, 出现次数> 对存放在 map 里, 每读入一行, 就取到国家名, 然后在 map 里递增一下; 最后把国家名进行排序, 按从小到大进行输出. 要点:
使用 sort(countries.begin(), countries.end(), less<string>()); 进行从小到大排序. 题目:
代码:
# include # include # include # include # include # include # include # include # include # include
环境: C++ 4.5.3 - GNU C++ Compiler with options: -lm -lcrypt -O2 -pipe -DONLINE_JUDGE
UPDATE: