您的位置:首页 > 其它

Oulipo

2015-07-07 18:26 411 查看

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

#include<iostream>

#include<string>

using namespace std;

int next1[100002];

int mount;

void getnext(string s)

{

 int i=0,j=-1;

 next1[0]=-1;

 while(i<s.size())

 {

  if(j==-1 || s[i]==s[j])

  {

   i++;

   j++;

   next1[i]=j;

  }

  else

   j=next1[j];

 }

}

void match(string w,string t)

{

 int i=0,j=0;

 while(i<t.size())

 {

  if(j==-1 || t[i]==w[j])

   i++,j++;

  else

   j=next1[j];

  if(j==w.size())

  {

   mount++;

   j=next1[j];

  }

 }

}

int main()

{

// freopen("C:\\Users\\John\\Desktop\\hi.txt","r",stdin);

 int t1;

 string w,t;

 cin>>t1;

 while(t1--)

 {

  mount=0;

  cin>>w>>t;

  if(t.size()<w.size())

  {

   cout<<"0"<<endl;

   continue;

  }

  getnext(w);

  match(w,t);

  cout<<mount<<endl;

 }

 return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: