Clairewd’s message
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3669 Accepted Submission(s): 1411
Problem Description
Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important messages and she was preparing for sending it to ykwd. They had agreed that each letter of these messages would be transfered to another
one according to a conversion table.
Unfortunately, GFW(someone's name, not what you just think about) has detected their action. He also got their conversion table by some unknown methods before. Clairewd was so clever and vigilant that when she realized that somebody was monitoring their action, she just stopped transmitting messages.
But GFW knows that Clairewd would always firstly send the ciphertext and then plaintext(Note that they won't overlap each other). But he doesn't know how to separate the text because he has no idea about the whole message. However, he thinks that recovering the shortest possible text is not a hard task for you.
Now GFW will give you the intercepted text and the conversion table. You should help him work out this problem.
Unfortunately, GFW(someone's name, not what you just think about) has detected their action. He also got their conversion table by some unknown methods before. Clairewd was so clever and vigilant that when she realized that somebody was monitoring their action, she just stopped transmitting messages.
But GFW knows that Clairewd would always firstly send the ciphertext and then plaintext(Note that they won't overlap each other). But he doesn't know how to separate the text because he has no idea about the whole message. However, he thinks that recovering the shortest possible text is not a hard task for you.
Now GFW will give you the intercepted text and the conversion table. You should help him work out this problem.
Input
The first line contains only one integer T, which is the number of test cases.
Each test case contains two lines. The first line of each test case is the conversion table S. S[i] is the ith latin letter's cryptographic letter. The second line is the intercepted text which has n letters that you should recover. It is possible that the text is complete.
T<= 100 ;
n<= 100000;
Each test case contains two lines. The first line of each test case is the conversion table S. S[i] is the ith latin letter's cryptographic letter. The second line is the intercepted text which has n letters that you should recover. It is possible that the text is complete.
Hint
Range of test data:T<= 100 ;
n<= 100000;
Output
For each test case, output one line contains the shorest possible complete text.
Sample Input
2 abcdefghijklmnopqrstuvwxyz abcdab qwertyuiopasdfghjklzxcvbnm qwertabcde
Sample Output
abcdabcd qwertabcde
题目大意:第一格串是a-z字母对应的密文,
第二个串由完整的密文,和可能完整,可能不完整,可能不存在的明文组成
判断最短的完整密文+完整明文的串是什么
题目分析:直接算取next数组之后,判断当i >=(len-1)/2时,是否存在 next[len] >= len -i , 如果存在证明当前密文可以由后面的明文翻译出来
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#define MAX 100007
using namespace std;
int t;
char s1[MAX];
char s2[MAX];
char fmp[MAX];
int Next[MAX];
void get_next ( )
{
int i = 0 , k = -1 , len = strlen(s2);
Next[0] = -1;
while ( i <= len )
if ( k == -1 || s2[i] == fmp[s2[k]] )
i++,k++,Next[i] = k;
else k = Next[k];
}
int main ( )
{
scanf ( "%d" , &t );
while ( t-- )
{
scanf ( "%s" , s1 );
scanf ( "%s" , s2 );
int len1 = strlen (s1);
int len2 = strlen (s2);
for ( int i = 0 ; i < len1 ; i++ )
fmp[s1[i]] = (char)('a'+i);
get_next ( );
int len = len2;
for ( int i = (len2-1)/2 ; i++ ; i <= len2 )
if ( Next[len2] >= len2-i )
{
len = i;
break;
}
for ( int i = 0 ; i < len ; i ++ )
printf ( "%c" , s2[i] );
for ( int i = 0 ; i < len ; i ++ )
printf ( "%c" , fmp[s2[i]] );
puts ( "" );
}
}