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)