程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> hdu4300 Clairewd’s message

hdu4300 Clairewd’s message

編輯:關於C++
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字母表,這些代表的是原來順序的字母表變成密文後所對應的字母,如樣例中的qwertyuiopasdfghjklzxcvbnm,那麼原來的'a'就變成了'q','b'變成了'w'.然後再給你一個字符串,裡面包含了密文和原文,其中順序一定是先密文,後原文,但原文不一定寫全,可能有缺少,問你把密文和明文補充完整輸出。

思路:因為密文一定比明文長或者相等,所以(len-1)/2個字符一定是密文,先把它們轉化為明文,然後和後面的明文進行匹配,看最後從哪個字符開始後面的所有字符可以和密文匹配,一直到最後,那麼這個字符就是明文的開始。然後就可以先輸出密文,再輸出明文了。

 

#include
#include
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

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved