谁会作C语言题呀!急急急帮下忙呀

来源:百度知道 编辑:UC知道 时间:2024/05/29 08:32:02
在若干个单词中找到含有"ab"的单词并输出

//在若干个单词中找到含有"ab"的单词并输出
#include <stdio.h>
#include <string.h>
main()
{
char str[80];
char *p;
char c;
int flag=0;
puts("input str:");
gets(str);
p=str;
while(*p)
{
if(*p=='a')
{
flag=1;
p++;
}
else
p++;
if(flag==1&&*p=='b')
{
flag=2;
break;
}
else if(flag==1&&*p!='b')
{
flag=0;
p++;
}
}
if(flag==2)
printf("%s have ab.",str);
else
printf("%s haven't ab.",str);

}

//在若干个单词中找到含有"ab"的单词并输出
#include <iostream>
#include <string>
#define N 3
using namespace std;
void main(){
string s[N];
int i;
for( i=0;i<N;i++){
cout<<"输入一个字符串"<<endl;
cin>>s[i];
}