hdu 4300 Clairewd’s message (kmp)
2015-10-01 21:07
393 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4300
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.
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.
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
题意就是给你26的字母的加密方式,然后又给了一个串s1是包含加密后的和没有加密的但是没有加密的可能不齐全;求完整的密文和原文;
例如第二个例子:
abcdefghijklmnopqrstuvwxyz
加密方式: qwertyuiopasdfghjklzxcvbnm
s1: qwertabcde
在s1中qwert就是密文,后面的abcde就是原文;
假如加密方式不变,s1变成qwertabc,那么答案还是qwertabcde;
密文的长度肯定大于s1总长度的一半,我们可以把s1前一半当成密文后一半不变,然后解密得到s2,那么s2的Next【len】就是给出的明文的长度,总长度-明文
的长度得到的就是密文的总长度,然后输出密文和密文对应的明文就可以了;
Clairewd’s message
Problem DescriptionClairewd 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.
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.
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
题意就是给你26的字母的加密方式,然后又给了一个串s1是包含加密后的和没有加密的但是没有加密的可能不齐全;求完整的密文和原文;
例如第二个例子:
abcdefghijklmnopqrstuvwxyz
加密方式: qwertyuiopasdfghjklzxcvbnm
s1: qwertabcde
在s1中qwert就是密文,后面的abcde就是原文;
假如加密方式不变,s1变成qwertabc,那么答案还是qwertabcde;
密文的长度肯定大于s1总长度的一半,我们可以把s1前一半当成密文后一半不变,然后解密得到s2,那么s2的Next【len】就是给出的明文的长度,总长度-明文
的长度得到的就是密文的总长度,然后输出密文和密文对应的明文就可以了;
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <cstdlib> #include <limits> #include <queue> #include <stack> #include <vector> #include <map> using namespace std; #define N 101000 #define INF 0x3f3f3f3f #define PI acos (-1.0) #define EPS 1e-8 #define met(a, b) memset (a, b, sizeof (a)) char s1 , s2 , s3 ; int Next , n; void get_next (char s[], int n); int main () { int t; scanf ("%d", &t); while (t--) { scanf ("%s %s", s1, s2); int len2 = strlen (s2); int len1 = strlen (s1); int k = 0; for (int i=0; i<len2/2; i++) { for (int j=0; j<len1; j++) if (s2[i] == s1[j]) s3[k++] = 'a' + j; } s3[k++] = '*'; for (int i=len2/2; i<len2; i++) s3[k++] = s2[i]; get_next (s3, k); int ans = Next[k]; printf ("%s", s2); for (int i=ans; i<len2-ans; i++) for (int j=0; j<len1; j++) if (s2[i] == s1[j]) printf ("%c", 'a' + j); puts (""); } return 0; } void get_next (char s[], int n) { int i = 0, j = -1; Next[i] = -1; while (i < n) { if (j == -1 || s[i] == s[j]) Next[++i] = ++j; else j = Next[j]; } }
相关文章推荐
- RAID的原理和应用
- Linux守护进程设计规范及python实现http://blog.csdn.net/dysj4099/article/details/18219411
- 【解决方法】Setup script exited with error: command 'cc' failed with exit status 1
- Raid控制器
- Aizu 2309 Sleeping Time DFS
- POJ 3216 Repairing Company (floyd + 最小路径覆盖)
- Aizu 2304 Reverse Roads(无向流)
- system函数源码 http://blog.csdn.net/ericming200409/article/details/5416234
- RAID
- LightOJ 1236 Pairs Forming LCM
- Aizu 2300 Calender Colors(暴力)
- Aizu 2301 Sleeping Time(概率,剪枝)
- Aizu 2303 Marathon Match (概率)
- org.hibernate.LazyInitializationException: failed to lazily initialize no session or session was clo
- raid各级别特性
- LightOJ 1282 Leading and Trailing
- root@kali:~# insmod /usb/serial/cp210x.ko :Unknown symbol in module
- 1014. Waiting in Line (30) 模拟银行排队
- JMeter一个错误the target server failed to respond--JMeter坑
- Service Manager流程,派BC_REPLY,唤醒FregServer流程,返回BR_TRANSACTION_COMPLETE,睡眠等待proc->wait