zoukankan      html  css  js  c++  java
  • Oulipo POJ

    //以前没分类过 现在该分类一下了
    #include <iostream> #include <algorithm> #include <stdio.h> #include <set> #include <queue> #include <cstring> #include <string> #include <limits.h> #include <string.h> #include <vector> #include <map> #define LL long long #define INF 2100000000 #define fi first #define se second #define lowbit(x) (x&(-x)) #define eps 5e-7 using namespace std; const int maxn=(int)1e6 +10; const int maxm=(int)1e4+10; const LL MOD=(LL)1e9+7; int next1[maxm]; void kmppre(char x[]) { int i,j; j=next1[0]=-1; //next[i]表示在第i个字符失配后, //模式串中0->next[i]处仍为匹配状态 i=0; while(x[i]) { while(j!=-1&&x[i]!=x[j]) j=next1[j]; next1[++i]=++j; } } int kmpcount(char x[],char y[]){ int i,j,ans=0; kmppre(x); i=j=0; while(y[i]){ while(j!=-1&&y[i]!=x[j])j=next1[j]; i++;j++; if(!x[j]){ ans++;j=next1[j]; } } return ans; } char s1[maxm],s2[maxn]; int main() { #ifdef shuaishuai freopen("C:\Users\hasee\Desktop\a.txt","r",stdin); //freopen("C:\Users\hasee\Desktop\b.txt","w",stdout); #endif int t; scanf("%d ", &t); while(t--){ gets(s1);gets(s2); printf("%d ",kmpcount(s1,s2)); } return 0; }
  • 相关阅读:
    面试开发需要准备的
    多线程 多进程
    TCP/IP协议学习
    深信服算法岗实习面试经验
    TZOJ4777: 方格取数
    Python 基于 NLP 的文本分类
    mac os 使用记录
    字节跳动游戏开发岗题目
    mac进行acm(C/C++)编程
    常用的正则表达式(转)
  • 原文地址:https://www.cnblogs.com/MeowMeowMeow/p/7504254.html
Copyright © 2011-2022 走看看