hdu4300 Clairewd’s message
来源:互联网 发布:ucsc数据库预测乙酰化 编辑:程序博客网 时间:2024/05/16 09:32
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这道题花了很长时间啊。。。题意也很长时间才看懂,题意是这样的:给你一个26字母表,这些代表的是原来顺序的字母表变成密文后所对应的字母,如样例中的qwertyuiopasdfghjklzxcvbnm,那么原来的'a'就变成了'q','b'变成了'w'.然后再给你一个字符串,里面包含了密文和原文,其中顺序一定是先密文,后原文,但原文不一定写全,可能有缺少,问你把密文和明文补充完整输出。
思路:因为密文一定比明文长或者相等,所以(len-1)/2个字符一定是密文,先把它们转化为明文,然后和后面的明文进行匹配,看最后从哪个字符开始后面的所有字符可以和密文匹配,一直到最后,那么这个字符就是明文的开始。然后就可以先输出密文,再输出明文了。
#include<stdio.h>#include<string.h>char s1[100006],s2[100006],s[100006],s3[100],s4[100006];int len1,len2,next[100006];void nextt(){int i,j;i=0;j=-1;memset(next,-1,sizeof(next));while(i<len2){if(j==-1 || s2[i]==s2[j]){i++;j++;next[i]=j;}else j=next[j];}}int kmp(){int i,j;i=0;j=0;while(i<len1 && j<len2){if(j==-1 || s1[i]==s2[j]){i++;j++;}else j=next[j];}return j;}int main(){int n,m,i,j,T,len,t,k;scanf("%d",&T);while(T--){memset(s1,0,sizeof(s1));memset(s2,0,sizeof(s2));scanf("%s%s",s3,s4);len=strlen(s4);for(i=0;i<len;i++){for(k=0;k<26;k++){if(s3[k]==s4[i]){s[i]='a'+k;break;}}if(i<=(len-1)/2)s2[i]=s[i];}for(i=(len-1)/2+1;i<len;i++){s1[i-(len-1)/2-1]=s4[i];}//printf("%s %s\n",s1,s2);nextt();len1=strlen(s1);len2=strlen(s2);t=len-kmp();//printf("%d\n",kmp());for(i=0;i<t;i++)printf("%c",s4[i]);for(i=0;i<t;i++){for(k=0;k<26;k++){if(s3[k]==s4[i]){printf("%c",'a'+k);}}}printf("\n");}return 0;}
0 0
- HDU4300:Clairewd’s message
- hdu4300---Clairewd’s message
- hdu4300 Clairewd’s message
- HDU4300 Clairewd’s message
- 【KMP】 hdu4300 Clairewd’s message
- HDU4300-Clairewd’s message-KMP
- HDU4300 Clairewd’s message 暴力/KMP算法
- hdu4300 Clairewd’s message(扩展KMP)
- hdu4300 Clairewd’s message 扩展KMP
- HDU4300 Clairewd’s message 扩展kmp
- hdu4300 Clairewd’s message(KMP)
- hdu4300 Clairewd’s message (字符串hash)
- HDU4300 Clairewd’s message(扩展KMP)
- HDU4300-Clairewd’s message(KMP前缀匹配后缀)
- HDU4300 Clairewd’s message(扩展KMP,后缀匹配前缀)
- [学习][HDU4300]字符串哈希 Clairewd's message
- Clairewd’s message +KMP
- Clairewd’s message (KMP)
- Caused by: java.sql.SQLException: ResultSet is from UPDATE. No Data.
- 那些我们卖掉的二手iPhone到底去哪了?
- 基于SDN的SVC视频组播系统搭建三
- LCA(离线算法)
- git学习
- hdu4300 Clairewd’s message
- 创建和销毁对象(一)
- LeetCode 80:Remove Duplicates from Sorted Array II
- ArrayList中元素判定相等方法
- 三种方法解决浮动元素父容器高度自适应问题
- Redis海量数据java测试代码
- jd—gui的不能全部翻译
- leetcode -Swap Nodes in Pairs
- arcgis server注册ecp时,提示“所选文件中未发现有效功能”解决办法