Match:blue Jeans (POJ 3080)

Source: Internet
Author: User

                

DNA sequence

The main idea: to give you a string of M strings, you want to find the longest of the same continuous word string

This violent KMP can be, note to order by dictionary order, at the same time, is len<3 output no significant commonalities

  

1#include <iostream>2#include <functional>3#include <algorithm>4#include <string.h>5 #defineMAX 606 7 using namespacestd;8 9typedefChar*_string;TentypedefintPosition; One Static Charstr[ One][ A],ans[ +]; A Static int_next[ +]; -  - BOOLKmpsearch (_string, _string,Const int); the voidGet_next (_string,Const int); - voidSearch (Const int); -  - intMainvoid)//violence Enumeration first line + { -     intcase_sum, M; +     //freopen ("In.txt", "R", stdin); Ascanf"%d", &case_sum); at  -      while(case_sum--) -     { -scanf"%d", &m); - GetChar (); -          in          for(inti =0; I < m; i++) -scanf"%s", Str[i]); to Search (m); +     } -     returnexit_success; the } *  $ voidSearch (Const intm)Panax Notoginseng { -     intLen, Ans_len =-1, POS, If_match; the     Chartmp; +  A      for(len =1; Len <= MAX; len++) the     { +          for(pos =0; POS + len <= MAX; pos++) -         { $If_match =0; $Get_next (&str[0][pos], Len); -              for(inti =1; I < m; i++) -If_match + = Kmpsearch (Str[i], &str[0][pos], Len); the             if(If_match = = M-1&& Len >=Ans_len) -             {Wuyi                 if(len = =Ans_len) the                 { -TMP = str[0][pos +Len]; Wustr[0][pos + len] =' /'; -                     if(strcmp (&str[0][pos], ans) <0) Aboutstrcpy (ans, &str[0][pos]); $str[0][pos + len] =tmp; -                 } -                 Else if(Len >Ans_len) -                 { AAns_len =Len; +TMP = str[0][pos +Len]; thestr[0][pos + len] =' /'; -strcpy (ans, &str[0][pos]); $str[0][pos + len] =tmp; the                 } the             } the         } the     } -     if(Ans_len <3) inprintf"no significant commonalities\n"); the     Else theprintf"%s\n", ans); About } the  the BOOLKmpsearch (_string str_m, _string text,Const intT_len) the { +Position i =0, j =0; -  the      while(I < MAX && J <T_len)Bayi     { the         if(j = =-1|| Str_m[i] = =Text[j]) the         { -i++; -J + +; the         } the         Elsej =_next[j]; the     } the     if(J = =T_len) -         return true; the     Else the         return false; the }94  the voidGet_next (_string text,Const intT_len) the { thePosition i =0, k =-1;98_next[0] = -1; About  -      while(I <T_len)101     {102         if(k = =-1|| Text[i] = =Text[k])103         {104i++; thek++;106_next[i] = text[i]! = text[k]?K: _next[k];107         }108         ElseK =_next[k];109     } the}

  

Match:blue Jeans (POJ 3080)

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.