HDOJ4300Clairewd’s message【扩展KMP】
来源:互联网 发布:数控编程的步骤是什么 编辑:程序博客网 时间:2024/05/06 04:07
Clairewd’s message
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4186 Accepted Submission(s): 1597
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
2abcdefghijklmnopqrstuvwxyzabcdabqwertyuiopasdfghjklzxcvbnmqwertabcde
Sample Output
abcdabcdqwertabcde
给定一个明文和密文的换算表给定一串字符串前面为密文完整后面为明文不完整求出最短的密文并输出明文和密文
#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;const int MAX=1000010;int next[MAX];int extend[MAX];int MIN(int a,int b){return a<b?a:b;}char table[30];void getNext(char *T){int i,lenT=strlen(T);next[0]=lenT;for(i=0;i<lenT-1&&T[i]==table[T[i+1]-'a'];++i);next[1]=i;int a=1;for(int k=2;k<lenT;++k){int p=a+next[a]-1,L=next[k-a];if((k+L-1)>=p){int j=(p-k+1)>0?(p-k+1):0;while(k+j<lenT&&T[j]==table[T[k+j]-'a'])++j;next[k]=j;a=k;}else {next[k]=L;}}}char str[MAX];char zhuanhuan[30];int main(){int t,i,j;scanf("%d",&t);while(t--){scanf("%s",table);scanf("%s",str);for(i=0;i<26;++i){zhuanhuan[table[i]-'a']='a'+i;}memset(next,0,sizeof(next));getNext(str);int len=strlen(str);for(i=(strlen(str)+1)/2;i<len;++i){ if(next[i]==len-i)break;}for(j=0;j<i*2;++j){if(j>=i){printf("%c",zhuanhuan[str[j-i]-'a']);}else {printf("%c",str[j]);}}printf("\n");}return 0;}
0 0
- HDOJ4300Clairewd’s message【扩展KMP】
- hdu 4300 Clairewd’s message 扩展kmp
- HDOJ 4300 Clairewd's message(扩展KMP)
- hdu 4300 Clairewd’s message(扩展KMP)
- HDU 4300 Clairewd’s message(扩展KMP)
- 【扩展KMP】 HDOJ 4300 Clairewd’s message
- hdu 4300 Clairewd’s message (扩展kmp)
- hdu4300 Clairewd’s message(扩展KMP)
- hdu4300 Clairewd’s message 扩展KMP
- HDU4300 Clairewd’s message 扩展kmp
- HDU4300 Clairewd’s message(扩展KMP)
- HDU 4300Clairewd’s message 扩展kmp || kmp
- MUTC 1 A - Clairewd’s message 扩展KMP
- hdu 4300 Clairewd’s message(详解,扩展KMP)
- HDU 4300 Clairewd’s message(扩展KMP)
- HDU 4300 Clairewd’s message(扩展kmp)
- HDU-4300 Clairewd’s message + 4333(扩展KMP)
- hdu 4300 Clairewd’s message(扩展KMP)
- Alignment
- Codeforces Round #316 (Div. 2) E
- pat(A)1074. Reversing Linked List(哈希)
- HDU 4598 Difference 差分约束 + 判奇圈
- uva 11383 Golden Tiger Claw (KM算法)
- HDOJ4300Clairewd’s message【扩展KMP】
- 卡券创建Json字段解析
- 00 声明
- Linux内核设计与实现--学习笔记--第二章
- 剖析SSH核心原理(一) .
- 偏导项不能相消
- POJ 3685 Matrix(二分套二分)
- 博弈论-巴什博弈、威佐夫博奕、尼姆博奕
- ./configure --with参数