有关字符串查找的问题

来源:互联网 发布:opengl es3.0编程指南 编辑:程序博客网 时间:2024/05/18 00:49

 

//比如说现在有一个程序,要求用户一个字符串一个字符串的输入,如果当前所输入的字符串和之前所输入的字符串有所重复,则打印字符串重复的信息!如果输入结束时没有//重复则在最后打印无字符串重复的信息!//下面的例子如下:假设按照如下的字符串输入顺序输入字符串 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;}

原创粉丝点击