关联容器map应用-统计单词出现频率
来源:互联网 发布:hifi播放器 知乎 编辑:程序博客网 时间:2024/05/22 04:30
以下程序实现:从1.txt中读入英文句子,统计每个单词出现的频率,按照字典顺序输出。
知识点:关联容器map
#include<iostream>
#include<string>
#include<fstream>
#include <algorithm>
#include<map>
using namespace std;
ifstream & open_file(ifstream& in, const string& name){
in.close();
in.clear();
in.open(name.c_str());
return in;
}
int main(){
map<string, int> word_count;
ifstream if1;
if(!open_file(if1,"1.txt")){cout<<"open file 1.txt failed!"<<endl; return 0;}
string word;
while (if1>>word){
transform(word.begin(),word.end(),word.begin(),tolower);
++word_count[word];
}
map<string, int>::iterator map_it=word_count.begin();
while (map_it!=word_count.end()){
cout<<map_it->first<<":"<<map_it->second<<endl;
++map_it;
}
return 0;
}
- 关联容器map应用-统计单词出现频率
- 统计单词频率-map
- 作业,统计单词出现频率
- Java统计单词出现频率
- poj 2418 map入门(统计单词频率)
- 利用树统计单词出现的频率
- 统计文件中单词出现的频率
- 统计英文文本单词出现频率
- 统计文本中英文单词的出现频率
- Python 统计文章单词出现频率
- 统计一篇短文中单词出现频率
- Java统计单词频率
- 统计一TXT文档中单词出现频率,输出频率最高的10个单词
- map下统计单词出现的地方
- 统计一篇文章中单词出现的频率
- 统计文章出现频率最高的单词 2011211554
- 统计历年6级真题及答案中单词出现频率
- STL统计英文中单词出现频率的问题
- 【特殊的图+DP】【11月校赛】大家一起玩游戏
- Erlang二进制数据处理
- PagedList
- 图形化GDB调试(TUI模式)
- 特殊三位数——(满足n=a!+b!c!的所有三位数n,a,b,c,分别是n的百,十,个位数)
- 关联容器map应用-统计单词出现频率
- Xamarin.Android之下拉刷新
- n-Gram
- Android Touch事件传递机制解析
- C++中的关联容器map用法
- Git 操作实战示例(四)
- Window 8 启用 Telnet 命令工具一览图
- Java泛型与Restlet客户端
- 查看当前Android版本RemoteViews支持的UI对象