输入字符串,找出该字符串中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;
}
}
#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;
}
}
相关文章推荐
- 输入一行子串,找出其中出现的相同且长度最长的字符串,输出它及其首字符的位置
- 输入一行字符串,找出其中重复出现且最长的字符串,输出它及其首字符的位置
- 输入一行字符串,找出其中出现的相同且长度最长的字符串,输出他及其首字符串位置
- 输入一行字符串,找出其中重复出现且最长的字符串,输出它及其首字符的位置
- 输入一行字符串,找出其中出现的相同且长度最长的字符串,输出它及其首字符的位置
- 输入一行字符串,找出出现的相同且长度最长的字符串,输出它及其首字母的置比如:“yyabcdagaerabceg”答案应该是abc
- 找出A字符串中出现B字符串的起始位置
- 从字符串1中找出字符串2出现的位置以及个数
- 【笔试题】C语言:在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出&#39;b&#39;。
- 输入一行字符串,找出其中出现的相同且长度最长的字符串
- C# 找出一个子串在另一字符串中出现的所有位置
- 【C语言】在字符串中找出第一个只出现一次的字符,输入“abaccdeff”,则输出'b'
- 给出一个字符串,找出其中只出现一次且位置最靠前的那个字符
- C语言:在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出&#39;b&#39;
- 程序员面试宝典:输入一行字符串,找出其中出现的相同且长度最长的字符串----后缀数组求解
- 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始)。如果不存在,则返回 -1。
- 在字符串中找出第一个只出现一次的字符串,如输入"abaccdeff",输出'b'
- 【C语言】在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出’b’
- 【笔试题】C语言:在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出'b'。
- 找出字符串中第一个只出现过一次的字符和位置