Clairewd’s message

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3433    Accepted Submission(s): 1334

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
 
Author
BUPT
 
Source
大意:  首先给你一个暗纹表,然后第二行给你一个包含暗纹和名文的的字符串,要你解析出明文... (很屌炸天的英文描述,完全不知道要表达什么,从去年就想做这道题,一看,不明白题意思就放下了...)
代码:
 

 #include<cstring>
#include<cstdio>
#include<map>
using namespace std;
const int maxn=;
char stdch[]; //给出的暗文标准版
map<char,int>str;
char text[maxn];
char tes[maxn];
int next[maxn];
void getnext(int len){
int i=,j=-;
//memset(next,0,sizeof(next));
next[]=-;
while(i<len){
if(j==-||tes[i]==tes[j]){
i++;
j++;
// next[i]=j; 优化一下
if(tes[i]!=tes[j]) next[i]=j;
else next[i]=next[j];
}
else j=next[j];
}
}
void kmp(int len){ //前半部是暗纹,后半部是明文,所以起点:i
//tes是经过翻转之后的暗纹,也就是明文
getnext(len);
int len1=len;
if(len1&)len1++; //这里需要特别注意因为暗纹要不明文长,明文可以又缺失
int i=len1>>,j=;
while(i<len&&j<len){
if(j==-||text[i]==tes[j]){
i++;
j++;
}
else j=next[j];
}
printf("%s",text);
if(j*!=len) {
for(int i=j;i+j<len;i++)
printf("%c",tes[i]);
}
puts("");
}
int main(){
int test;
//freopen("test.in","r",stdin);
scanf("%d",&test);
while(test--) { if(!str.empty()) str.clear();
scanf("%s",stdch);
for(int i=;i<;i++)
str[stdch[i]]=i;
scanf("%s",text);
int tslen=strlen(text);
for(int i=;i<tslen;i++){
tes[i]=str[text[i]]+'a'; //经过两次旋转
}
kmp(tslen);
}
return ;
}

hdu------(4300)Clairewd’s message(kmp)的更多相关文章

  1. hdu 4300 Clairewd’s message KMP应用

    Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...

  2. HDU 4300 Clairewd’s message(KMP+思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...

  3. HDU - 4300 Clairewd’s message (拓展kmp)

    HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...

  4. hdu 4300 Clairewd’s message 字符串哈希

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. hdu 4300 Clairewd’s message(具体解释,扩展KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...

  6. hdu 4300 Clairewd’s message(扩展kmp)

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  7. hdu 4300 Clairewd’s message(kmp/扩展kmp)

    题意:真难懂.. 给出26个英文字母的加密表,明文中的'a'会转为加密表中的第一个字母,'b'转为第二个,...依次类推. 然后第二行是一个字符串(str1),形式是密文+明文,其中密文一定完整,而明 ...

  8. HDU 4300 Clairewd's message ( 拓展KMP )

    题意 : 给你一个包含26个小写字母的明文密文转换信息字符串str,第一个表示'a'对应的密文是str[0].'b'对应str[1]……以此类推.接下来一行给你一个另一个字符串,这个字符串由密文+明文 ...

  9. HDU 4300 Clairewd’s message(扩展KMP)

    思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...

  10. HDU 4300 Clairewd’s message(扩展KMP)题解

    题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...

随机推荐

  1. CodeForces 146A Lucky Ticket

    Lucky Ticket Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  2. PHP clone

    PHP  clone     定义一个电视类 class Tv{public $width=100;public function setWidth($v){$this->width = $v; ...

  3. windows c dll的创建与调用

    DLL代码: // TestDynamic.cpp: implementation of the TestDynamic class. // ///////////////////////////// ...

  4. Logical Databases逻辑数据库

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. 虚拟机guest为windows7的环境下安装破解版simplify3d_3.0.2

    情形: 1.主机(host):ubuntu 2.虚拟机里安装的操作系统版本(guest):windows 7专业版 3.simplify3d破解版版本:3.0.2(破解需要的工具均在下文的百度云地址里 ...

  6. v9 推荐位 排序问题解决办法

    原网站:http://bbs.phpcms.cn/thread-879943-1-1.html 简介: 用phpcms做网站的时候,有些地方要用到推荐位列表,如幻灯片,特别推荐等.有时候因为文章的重要 ...

  7. JAVA中在Myeclipse里把表导入成相应的poco实体类

    参考:地址: http://blog.csdn.net/jintaiyong/article/details/7383982

  8. ZOJ-2362 Beloved Sons 最大权值匹配

    题意:国王有N个儿子,现在每个儿子结婚都能够获得一定的喜悦值,王子编号为1-N,有N个女孩的编号同样为1-N,每个王子心中都有心仪的女孩,现在问如果安排,能够使得题中给定的式子和最大. 分析:其实题目 ...

  9. E2 2014.08.05 更新日志

    增加功能 增加手机.平板兼容模块,用手机平板也能正常登陆和使用软件 介绍  演示 对数据库全面优化,全面提升数据量很大时统计分析的性能 完善功能 销售分析增加按商品分类分析 完善客户明细窗口的客户信息 ...

  10. javascript中怎么让一个页面执行多个window.onload?

    我们都知道在javascript中window.onload 只能有一个如果有多个的话后面的会覆盖前面的,今天我们来看看怎么让一个页面执行多个window.onload <script type ...