69,370
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#define MAX 20
int test()
{
if('a'=='a')
return 10;
else
return 0;
}
int main()
{
// int te;
//te=test();
//printf("%d",te);
char ch;
char ch1[MAX];
char ch2[MAX];
int lengthCh1=0;
int lengthCh2=0;
bool flag=false;
bool flag1=false;
scanf("%c",&ch);
while(ch!='$')
{
ch1[lengthCh1++]=ch;
scanf("%c",&ch);
}
ch1[lengthCh1++]='\0';
scanf("%c",&ch);
while(ch!='$')
{
ch1[lengthCh2++]=ch;
scanf("%c",&ch);
}
ch1[lengthCh2]='\0';
printf("%d\n",lengthCh2-1);
printf("%d\n",lengthCh1-1);
int posCh2=0;
int k;
for(int posCh1=0; posCh1<lengthCh1-1 ; posCh1++)
{
k= posCh1;
printf("dgj\n" );
while(ch2[posCh2]==ch1[k])
{
k++;
posCh2++;
flag1=true;
printf("%d\n",posCh2);
if( posCh2>=lengthCh2-1)
{
//flag=true;
printf("success\n");
exit(0);
}
}//while
if(flag1)
{
posCh1=k-1;
flag1=false;
}
else posCh1=k;
posCh2=0;
}//for
if(!flag) printf("fail\n");
// else printf("success\n");
return 0;
}
char * __cdecl strstr (
const char * str1,
const char * str2
)
{
char *cp = (char *) str1;
char *s1, *s2;
if ( !*str2 )
return((char *)str1);
while (*cp)
{
s1 = cp;
s2 = (char *) str2;
while ( *s1 && *s2 && !(*s1-*s2) )
s1++, s2++;
if (!*s2)
return(cp);
cp++;
}
return(NULL);
}
char * __cdecl strstr (
const char * str1,
const char * str2
)
{
char *cp = (char *) str1;
char *s1, *s2;
if ( !*str2 )
return((char *)str1);
while (*cp)
{
s1 = cp;
s2 = (char *) str2;
while ( *s1 && *s2 && !(*s1-*s2) )
s1++, s2++;
if (!*s2)
return(cp);
cp++;
}
return(NULL);
}
char * strstr(const char *str1, const char *str2)
{
char *c1, *c2, *s = (char *)str1;
if (!*str2)
return (char *)str1; /* return str1 if str2 is empty */
if (!*str1)
return NULL; /* return NULL if str1 is empty */
while(*s)
{
if (*s == *str2) /* wait for the first matching char */
{
c1 = s;
c2 =(char *) str2;
/* continue matching chars in the sub-str */
while (*c1 && *c2 && (!(*c2 - *c1)))
{
c2++;
c1++;
}
if (!*c2) /* if we've run off the end of str2 */
return s; /* then we've found the first substr match */
}
s++; /* otherwise try the next char */
}
return NULL; /* didn't find anything */
}
char *strstr( const char *s1, const char *s2)
{
size_t len2;
if ( !(len2 = strlen(s2)) ) return (char *)s1;
for ( ; *s1; ++s1 ) {
if ( *s1 == *s2 && strncmp( s1, s2, len2 )==0 ) return (char *)s1; }
return 0;
}