第一章查找单词例题-算法设计与分析报告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; 
	}

喜欢的话关注一下吧,打赏也行

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

酷爱码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值