http://acm.hdu.edu.cn/showproblem.php?pid=4150

查找不重复字串

View Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
char a[1100000],b[10];
int main()
{
int t,ans;
int len1,len2;
int cnt;
scanf("%d%*c",&t);
while(t--)
{
scanf("%s%s%*c",a,b);
len1=strlen(a);
len2=strlen(b);
ans=cnt=0;
for(int i=0;i<len1;i++)
{
if(cnt)
{
cnt--;
continue;
}
if(a[i]==b[0])
{
int f=1;
for(int j=1;j<len2;j++)
if(a[i+j]!=b[j])
{
f=0;
break;// 没有这个break会超时,汗、、、
}
if(f){
ans++;
cnt=len2-1;
}
}
}
printf("%d\n",ans);
}
return 0;
}