第一章查找单词例题-算法设计与分析报告C/C++版
  TEZNKK3IfmPf 2024年08月02日 44 0

设计如图

第一章查找单词例题-算法设计与分析报告C/C++版

PS:上面的设计报告pdf文档已上传,需要可以下载 

完整代码如下 

//author:rgh
#include<iostream>
#include<string>
#include<vector>
using namespace std;
void solve(string str,vector<string>&words)//产生所有单词
{
string w;
int i=0;
int j=str.find(" ");// 查找第一个空格
while(j!=-1)//找到单词后循环
{
w=str.substr(i,j-i);//提取一个单词
words.push_back(w);//将单词添加到words中
i=j+1;
j=str.find(" ",i);//查找下一个空格 
}

if(i<str.length()-1)//处理最后一个单词
{
w=str.substr(i);//提取最后一个单词
words.push_back(w);//最后单词添加到words中
}
}
int main()
{
	string str="The following code computes the intersection of two arrays";
	vector<string>words;
	solve(str,words);
	cout<<"所有的单词:"<<endl;//输出结果
	vector<string>::iterator it;
	for(it=words.begin();it!=words.end();++it)
	cout<<" "<<*it<<endl;
	return 0; 
	}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2024年08月02日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   10天前   18   0   0 编程开发
  TEZNKK3IfmPf   10天前   16   0   0 编程开发
  TEZNKK3IfmPf   10天前   20   0   0 编程开发i++
  TEZNKK3IfmPf   10天前   22   0   0 编程开发
TEZNKK3IfmPf