| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
AC#include<cstdio> #include<cstring> const int N=1000005; char s[N]; char k[N]; int f[N]; int len,len1; int ans=0; void make () { f[0]=-1; int i=1,j=-1; for (;i<len;i++) { while (j!=-1&&s[i]!=s[j+1]) j=f[j]; if (s[i]==s[j+1]) j++; f[i]=j; } return ; } void get_ans() { ans=0; int i=0,j=-1; for (;i<len1;i++) { while (j!=-1&&k[i]!=s[j+1]) j=f[j]; if (k[i]==s[j+1]) j++; if (j==len-1) { ans++; j=f[j]; } } return ; } int main() { int T; scanf("%d",&T); while (T--) { scanf("%s%s",s,k); len=strlen(s); len1=strlen(k); make(); get_ans(); printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator