计算一段字符串中单词的个数
来源:互联网 发布:windows live 软件包 编辑:程序博客网 时间:2024/04/30 07:16
#include<iostream>#include<fstream>#include <string>#include <map>using namespace std;void CountWords(){//ifstream is("/*打开输入文件*/");//ofstream os("/*打开输出文件*/");map<string,int> mp;map<string,int>::iterator it;string str;getline(cin,str);int j=0;int len=str.length();for (int i=0;i<len;i++){if (str[i]==' '||i==len-1){if (i==len-1){i++;}string tmp=str.substr(j,i-j);mp[tmp]++;j=i+1;}}while(cin>>str){if(str =="EOF")break;++mp[str];}for(it=mp.begin();it!=mp.end();it++) //遍历 { cout<<it->first<<' '<<"occurs "<<it->second<<endl; }}void main(){CountWords(); cout<<endl;system("pause");}
0 0
- 计算一段字符串中单词的个数
- 计算字符串中单词个数
- 字符串中单词的个数
- Java中计算相同单词的个数
- 计算txt文本中单词的个数
- 计算单词的个数
- 计算单词的个数
- 计算单词的个数
- 求字符串中单词的个数
- 统计字符串中单词的个数
- 输出一个字符串中单词的个数
- 统计字符串中单词的个数
- 统计字符串中单词的个数
- 字符串中不重复的单词个数
- 第十六周项目2------4 计算字符串中单词个数
- 用c语言实现 计算一个字符串中单词的个数
- 字符串中单词的个数以及最大长度单词求解
- 使用Map集合计算字符串单词的个数
- Scaena Felix 5479 (栈)
- 【软考】——原码、反码、补码、移码
- centos 6.5 svn安装和使用
- 对于JavaScript prototype的理解
- python中执行命令行的方法
- 计算一段字符串中单词的个数
- hdu 5480 Conturbatio 线段树
- 前端MV*框架之经典MVC
- 调试伺服的问题
- Bootstrap小练习------插件系列
- 前端MV*框架之MVP
- 浅识异常
- Machine Learning Basics(要点)
- sqlserver分页查询语句