我改了改,你看行不行#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define max 80
typedef struct {
char ch[max+1];
int length;
}SString;
int Index_BF(SString S , SString T )
{
int i=0,j=0;
while(i <S.length && j < T.length){
if(S.ch[i] == T.ch[j] ){
i++;
j++;
}else{
i=i-j+2;
j=1;
}
}
if(j == T.length){
return 1;
}else{
return 0;
}
}
int StrAssign(SString *S , char str[])
{
if(!S)
{
return 0;
}
int i;
for(i = 0 ; str[i] != '\0' ; i ++)
{
if(i <= max)
S->ch[i] = str[i];
else
break;
}
S->length = i;
return 1;
}
int Intsstring(SString *S)
{
return S->length = 0;
}
int main(int argc, char** argv) {
char virus[max];
char dna[max];
SString DNA,Viru;
Intsstring(&DNA);
Intsstring(&Viru);
int pos=0;
printf("请输入人的DNA:");
scanf("%s",dna);
printf("请输入病毒的DNA:");
scanf("%s",virus);
StrAssign(&DNA,dna);
StrAssign(&Viru,virus);
pos=Index_BF(DNA,Viru);
if(pos != 0){
printf("yes\n");
}else{
printf("no\n");
}
return 0;
}
|