您的位置:首页 > 其它

输入字符串,找出该字符串中abc出现的位置

2011-08-02 11:14 113 查看
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
vector<char> vec;
vector<char>::iterator it;
cout<<"输入第一个字符串"<<endl;
char ch;
while((ch=getchar())!='#')
vec.push_back(ch);
for(it=vec.begin();it!=vec.end();it++)
cout<<*it<<endl;
cout<<"输入第二个字符串"<<endl;
//while(ch=getchar())
char *s="abc";
int i=0;
for(i=0;i<vec.size();i++)
{
if(vec.at(i)==s[0])
cout<<s[0]<<"出现在第"<<i+1<<"个位置"<<endl;
cout<<"*******************************************************************"<<endl;
if(vec.at(i)==s[1])
cout<<s[1]<<"出现在第"<<i+1<<"个位置"<<endl;
cout<<"*******************************************************************"<<endl;
if(vec.at(i)==s[2])
cout<<s[2]<<"出现在第"<<i+1<<"个位置"<<endl;
cout<<"*******************************************************************"<<endl;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐