华为机试题之统计单词个数实例代码

前端之家收集整理的这篇文章主要介绍了华为机试题之统计单词个数实例代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

输入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; 
} 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

猜你在找的程序笔记相关文章