hdu 4300 Clairewd’s message
来源:互联网 发布:martin 旅行吉他知乎 编辑:程序博客网 时间:2024/05/10 18:28
Clairewd’s message
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2901 Accepted Submission(s): 1116
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
密文最小为(len+1)/2; 把后面的换成密文(比把前面换成明文效率高),然后根据next,判断密文终止位置,这样密文就得出来了,输出就很随意了
#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int MAXN = 100005;char pattern[MAXN];char tep[MAXN];char mp[26];int next[MAXN],T;void get_next(){ int m = strlen(pattern); int j=-1,i=0; next[i]=j; while(i<m){ if(j==-1 || pattern[i]==pattern[j]){ i++; j++; next[i]=j; }else j=next[j]; }}void kmp(int i){ int pos=i,j=0; while(pattern[i]){ if(j==-1 || pattern[i]==pattern[j]){ j++; i++; }else{ j=next[j]; pos = i-j; } } for(int i=0; i<pos; i++) cout<<tep[i]; for(int i=0; i<pos; i++){ for(int j=0; j<26; j++){ if(tep[i]==mp[j]) cout<<char(j+'a');//变成明文 } } cout<<endl;}int main(){ cin>>T; while(T--){ cin>>mp>>pattern; strcpy(tep,pattern); int len = strlen(pattern); for(int i = (len+1)/2 ; i < len ; i++){ //变成密文 int num = pattern[i]-'a'; pattern[i] = mp[num]; } get_next(); kmp((len+1)/2); } return 0;}
0 0
- hdu 4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- HDU-Clairewd’s message-4300
- hdu 4300 Clairewd’s message
- HDU 4300 Clairewd’s message
- HDU 4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- HDU 4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- HDU 4300 Clairewd’s message
- HDU 4300 Clairewd’s message
- HDU 4300 Clairewd’s message
- HDU-4300Clairewd’s message
- HDU 4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- HDU/HDOJ----4300 Clairewd’s message
- hdu 4300 Clairewd’s message 扩展kmp
- C语言中宏定义和函数的取舍
- java操作脚本的包script简介
- Oracle 11gR2 exp命令无法导出空表
- JAVA面试精选【Java算法与编程二】
- 使用STL vector 作为XNAMath快速灵活的SIMD数据容器
- hdu 4300 Clairewd’s message
- 流量变现
- 工业自动化4~20mA信号采集LED大屏动态显示技术方案
- 正规 从某字符到某字符之间的内容
- 自定义tabBarItem中的图片和文字样式
- “抢火车票”与程序猿思维 alpha
- 《Effective C++》学习笔记条款26 尽可能延后变量定义式的出现时间
- Java Swing中几种常见对话框(文件对话框、消息对话框、输入对话框、确认对话框、颜色对话框)
- 开发Android 的时候需卸载自己写的软件