博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
统计文本文件中单词出现次数最多的单词
阅读量:4356 次
发布时间:2019-06-07

本文共 506 字,大约阅读时间需要 1 分钟。

#include<iostream>

#include<string>
#include<map>
#include<fstream>

using namespace std;

int main()

{
 ifstream ifs("test.txt");
 map<string, int> M;
 map<string, int>::iterator iter;
 string t;
 while(getline(ifs, t))
 {
  M[t]++;
 }

 string maxStr;

 int max=0;
 for(iter = M.begin(); iter != M.end(); iter++)
 {
  if(iter->second > max)
  {
   maxStr = iter->first;
   max = iter->second;
  }
  
 }
 cout << maxStr << "   " << max << endl;
 system("pause");
 return 0;
}

转载于:https://www.cnblogs.com/xulb597/archive/2012/06/24/2560431.html

你可能感兴趣的文章
递归算法
查看>>
关于java中sendRedirect,forward和include区别
查看>>
在红帽RHEL7.0里配置网卡的四种方法
查看>>
LeetCode--二分查找相关算法
查看>>
RobotFramework自动化测试框架系统关键字之断言
查看>>
《Node.js In Action》笔记之流程控制
查看>>
通俗易懂云计算
查看>>
zigbee首次开通
查看>>
Hibernate查询-hql
查看>>
QT Creator 快速入门教程 读书笔记(三)
查看>>
bzoj 3811: 玛里苟斯【线性基+期望dp】
查看>>
Android的“再按一次返回键退出”的实现
查看>>
题目1014:排名
查看>>
团队开发1
查看>>
返回顶部
查看>>
Ext DateField控件 - 只选择年月
查看>>
Codeforces Round #342 (Div. 2) A. Guest From the Past(贪心)
查看>>
.Net基础
查看>>
Vue.js
查看>>
L2-001 紧急救援 [Dijkstra]
查看>>