首页 > 其他 > 详细

华为机试—统计单词个数(map)

时间:2015-01-12 09:20:01      阅读:337      评论:0      收藏:0      [点我收藏+]

输入n个单词,统计各个单词出现的个数

#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
	map<string,int> k;
	string word;

	while(cin>>word)
		++k[word];

	for(map<string,int>::iterator i=k.begin();i!=k.end();i++)
		cout<<(*i).first<<"\t"<<(*i).second<<endl;

	return 0;
}

技术分享

华为机试—统计单词个数(map)

原文:http://blog.csdn.net/wtyvhreal/article/details/42625109

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!