您的位置:首页 > 其它

有关字符串查找的问题

2012-06-19 16:47 176 查看
//比如说现在有一个程序,要求用户一个字符串一个字符串的输入,如果当前所输入的字符串和之前所输入的字符串有所重复,则打印字符串重复的信息!如果输入结束时没有//重复则在最后打印无字符串重复的信息!
//下面的例子如下:假设按照如下的字符串输入顺序输入字符串 now how big small world big……当输入到最后一个字符串也就是big的时候打印信息:字符串有所重复,否///则一直到程序结束打印无字符串重复!
//下面是源码:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
vector<string> strvec;
vector<string>::iterator str_iter=strvec.begin();
string str;
cout<<"please input the strings:"<<endl;
while((cin>>str)&&str!="end")
{
strvec.push_back(str);
str_iter=strvec.begin();
while(strvec.size()!=1&&str_iter!=strvec.end()-1&&*str_iter++!=str)
;//空语句
if(str_iter==strvec.end()-1)
continue;
else
cout<<"string repeated!"<<endl;
}
if(str=="end")
cout<<"no repeated!"<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: