hiho Week 3 register

Ended

Participants:669

Verdict:Accepted
Submitted:2014-07-25 12:35:08

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
#define maxn 1000001
char T[maxn],P[maxn];
int N,Plen,Tlen,next[maxn];
void getnext()
{
    Plen=strlen(P);
    int i=0,j=-1;
    next[i]=j;
    while(i<Plen){
        if(j==-1 || P[i]==P[j]){
            i++,j++,next[i]=j;
        }
        else j=next[j];
    }
}
int KMP()
{
    Tlen=strlen(T);
    int i=0,j=0,ans=0;
    while(i<Tlen)
    {
        if(P[j]==T[i]|| j==-1){
            i++,j++;
        }
        else j=next[j];
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX