Acdream Hut Freshman Training tournament D-Nana in Wonderland Series-the quirks of the villagers KMP

Source: Internet
Author: User

How to solve the problem: Jump count with next array.

Problem Solving Code:

1 //File name:d.cpp2 //Author:darkdream3 //Created time:2015 April 12 Sunday 19:40 52 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long -  - using namespacestd; - intN; - intT; in Charstr[300000]; - intLen; to intnext[300000]; + voidGet_next () - { thenext[0] = -1;  *     intK =-1;  $     intj =0 ; Panax Notoginseng      while(J <len) -     { the       if(k = =-1|| STR[J] = =Str[k]) +       { A++K; the++J; +NEXT[J] =K; -}Else{ $K =Next[k]; $       } -     } - } the intFindintx) - {Wuyi    if(x = =0) the        return 0;  -    return 1+find (Next[x]); Wu } - intMain () { Aboutscanf"%d",&t); $      while(t--) -     { -scanf"%s", str); -Len =strlen (str); Ascanf"%s",&Str[len]); +Len =strlen (str); the Get_next (); -printf"%d\n", find (len)); $     } the return 0; the}
View Code

Acdream Hut Freshman Training tournament D-Nana in Wonderland Series-the quirks of the villagers KMP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.