cth 2010-07-13 04:21:00
点我顶贴
收藏
删除
最最简单的字符串匹配算法,居然会有7个点的答案是错的。我无语了
#include<stdio.h>
#include<string.h>
char s1[10001],s2[10001];
int l1,l2,p[10001],count;
int find()
{
int i,j,t;
scanf("%s\n",&s1);
scanf("%s\n",&s2);
l1=strlen(s1);
l2=strlen(s2);
count=0;
for(i=0;i<l2-l1;i++)
{
if(s2[i]==s1[0])
{
t=1;
for(j=1;j<l1;j++)
{
if(s2[i+j]!=s1[j])
{
t=0;
break;
}
}
if(t)
{
count++;
p[count]=i+1;
}
}
}
if(count==0)
printf("There must be something wrong.");
else
{
printf("%d\n",count);
for(j=1;j<count;j++)
printf("%d\n",p[j]);
printf("%d",p[j]);
}
return 1;
}
int main()
{
find();
}