Clairewd ' s MESSAGE-HDU 4300 (next[] use)

Source: Internet
Author: User

The main topic: to two strings of the first string is a translation table (ciphertext can be translated into clear text), the second string is composed of ciphertext + clear text, the front is ciphertext (complete), followed by the plaintext (not necessarily complete), ask can be the second string complement, the output of the shortest possible.   Analysis: Test instructions comparison abstract ... Take a second example, qwertabcde-> qwert is ciphertext,abcde is clear text, ciphertext can pass above the QWERTYUIOPASDFGHJKLZXCVBNM (26 letters, each letter into its subscript letter q->a) translated into the back of the plaintext, so you should understand what's going on. And then know that the requirements come out short complement, to make complete the shortest, then ask for the suffix prefix of the maximum equal value is how much, and then the unmatched complement on the line, such as the first set of data Abcdab in order to prevent matching more than half (because the ciphertext is not missing, so the ciphertext is the least half), In the middle of the position plus a ' * ' division, became Abc*dab it is obvious that the final maximum match is 2, that is, the two behind is clear text, the front is ciphertext The code is as follows: =========================================================================================================== ==
#include <stdio.h>#include<string.h>Const intMAXN = 2e5+7;Const intOO = 1e9+7;Const intMoD =10007;CharS[MAXN], A[MAXN], PASS[MAXN];intNEXT[MAXN];voidGetNext (CharS[],intN) {    intI=0, j=-1; next[0] = -1;  while(I <N) {if(j==-1|| s[i]==S[j]) next[++i] = + +J; ElseJ=Next[j]; }}intMain () {intT; scanf ("%d", &T);  while(t--)    {        intI, N, Mid; scanf ("%s%s", S, a);  for(i=0; T[n]; i++) {pass[s[i]-'a'] = i+'a'; } N=strlen (a); Mid= (n+1)/2;  for(i=0; i<mid; i++) S[i]= pass[a[i]-'a' ]; S[i]='*', s[i+1]=0; Strcat (S, a+i); GetNext (S, N+1); Mid= n-next[n+1];  for(i=0; i<mid; i++) {S[i]=A[i]; S[i+mid] = pass[a[i]-'a' ]; } s[i+mid] =0; printf ("%s\n", s); }    return 0;}

Clairewd ' s MESSAGE-HDU 4300 (next[] use)

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.