第十章:单词出现次数程序
来源:互联网 发布:淘宝卖玉的哪家好 编辑:程序博客网 时间:2024/06/03 17:55
//通过建立map对象保存所读入的单词及其出现次数;
//统计并输出所读入的单词出现的次数;
//使用insert函数代替下标操作
#include <iostream>
#include <map>
#include <utility>
#include <string>
using namespace std;
int main()
{
map<string,int> wordCount;
string word;
//读入单词并统计其出现的次数
cout<<"enter some words(Ctrl+Z to end):"<<endl;
while(cin>>word)
{
//插入元素<word,1>
pair<map<string,int>::iterator,bool> ret=wordCount.insert(make_pair(word,1));
if(!ret.second)//该单词已在容器中存在
++ret.first->second;//将该单词出现的次数加1
}
//输出结果
cout<<"word\t\t"<<"times"<<endl;
for(map<string,int>::iterator iter=wordCount.begin();iter!=wordCount.end();++iter)
cout<<(*iter).first<<"\t\t"<<(*iter).second<<endl;
//用map对象的迭代遍历输出单词以及它出现的次数
map<string,int>::const_iterator map_it=wordCount.begin();
while(map_it!=wordCount.end())
{
cout<<map_it->first<<" occurs "<<map_it->second<<" times "<<endl;
++map_it;
}
return 0;
//统计并输出所读入的单词出现的次数;
//使用insert函数代替下标操作
#include <iostream>
#include <map>
#include <utility>
#include <string>
using namespace std;
int main()
{
map<string,int> wordCount;
string word;
//读入单词并统计其出现的次数
cout<<"enter some words(Ctrl+Z to end):"<<endl;
while(cin>>word)
{
//插入元素<word,1>
pair<map<string,int>::iterator,bool> ret=wordCount.insert(make_pair(word,1));
if(!ret.second)//该单词已在容器中存在
++ret.first->second;//将该单词出现的次数加1
}
//输出结果
cout<<"word\t\t"<<"times"<<endl;
for(map<string,int>::iterator iter=wordCount.begin();iter!=wordCount.end();++iter)
cout<<(*iter).first<<"\t\t"<<(*iter).second<<endl;
//用map对象的迭代遍历输出单词以及它出现的次数
map<string,int>::const_iterator map_it=wordCount.begin();
while(map_it!=wordCount.end())
{
cout<<map_it->first<<" occurs "<<map_it->second<<" times "<<endl;
++map_it;
}
return 0;
}
//通过建立map对象保存所读入的单词及其出现次数;
//统计并输出所读入的单词出现的次数;
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string,int> wordCount;
string word;
cout<<"enter some words(Ctrl+Z to end):"<<endl;
while(cin>>word)
++wordCount[word];
cout<<"word\t\t"<<"times"<<endl;
for(map<string,int>::iterator iter=wordCount.begin();iter!=wordCount.end();++iter)
cout<<(*iter).first<<"\t\t"<<(*iter).second<<endl;
return 0;
}
0 0
- 第十章:单词出现次数程序
- 统计单词出现次数
- 单词的出现次数
- 统计单词出现的次数
- baidu单词出现的次数
- 统计单词出现的次数
- 统计单词出现的次数
- 统计单词出现的次数。
- hadoop计算单词出现次数
- java按单词出现次数统计单词
- 统计单词出现的次数并按单词出现的次数顺序输出单词及其次数
- 意外收获-ruby编写的一个简单统计单词出现次数的程序
- 单词出现统计程序
- 查找单词出现次数[C实现]
- 统计文章中单词出现的次数
- 统计连续出现次数最多的单词
- 统计所有'单词'出现的次数
- Tire树 求出现次数最多单词
- 三种快速排序以及快速排序的优化
- C语言实现顺序栈的括号匹配
- SwipeRefreshListView
- 5种PHP创建数组的方式,你都了解哪些?
- MAC上安装node-canvas
- 第十章:单词出现次数程序
- VS2012导入COCOSx-2d 3.6项目的过程总结
- python装饰器
- 实现jquery EasyUI tabs选项卡关闭图标后加载自定义事件
- Java连接MySQL数据库
- 提取IP 地址(算法)
- SharePoint 2013 配置基于表单的身份认证
- HackingTeam重磅炸弹: 估值超1000万美金带有军火交易性质的木马病毒以及远控源码泄露
- 算法复习之选择排序