zoukankan      html  css  js  c++  java
  • Oulipo HDU

    #include<iostream>
    #include<cstring>
    using namespace std ;
    const int N=1e6+10;
    int n,m;
    int ne[N];
    char p[N],s[N];
    int main() {
    	int t;
    	cin>>t; 
    	while(t--) {
    		cin>>p+1>>s+1;
    		n=strlen(p+1);
    		m=strlen(s+1);
    		int ans=0;
    		for(int i=2,j=0; i<=n; i++) {
    			while(j&&p[i]!=p[j+1]) j=ne[j];
    			if(p[i]==p[j+1]) j++;
    			ne[i]=j;
    		}
    
    		for(int i=1,j=0; i<=m; i++) {
    			while(j&&s[i]!=p[j+1]) j=ne[j];
    			if(s[i]==p[j+1]) j++;
    			if(j==n) {
    				ans++;
    				j=ne[j];
    			}
    		}
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    条件
    循环
    列表
    字典
    集合
    公共操作
    函数-2
    函数-1
    函数加强
    文件操作
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12384459.html
Copyright © 2011-2022 走看看