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. 逐个后移,匹配符合要求的选项,ie7有bug

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. [CF733D]Kostya the Sculptor(贪心)

    题目链接:http://codeforces.com/contest/733/problem/D 题意:给n个长方体,允许最多两个拼在一起,拼接的面必须长宽相等.问想获得最大的内切圆的长方体序号是多少 ...

  3. Struts2-S2-032远程命令执行EXP

    看到网上好多写的EXP有后门啊  还是自己写个吧! 工具下载:链接: http://pan.baidu.com/s/1miRbi2k 密码: fzfv

  4. oracle学习笔记——配置环境

    题记:最近再学oracle,于是按照这本经典的书<Oracle Database 9i/10g/11g编程艺术>来学习. 配置环境 如何正确建立SCOTT/TIGER演示模式 需要建立和运 ...

  5. [SAP ABAP开发技术总结]ABAP常用事务码

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

  6. ubuntu14.04 64位系统下编译3.13.11内核源码

    该过程一共分为四步: 1.下载内核:我下载的是3.13.11这个版本的内核! 2.解压内核:我将其解压/home/jello/Downloads/linux-3.13.11目录下!下文将会基于此目录编 ...

  7. P2P小贷网站业务数据流程分享

    P2P小贷网站业务数据流程分享 引言 这是去年年底开发的一个项目,完成后和用户的衔接没有很好的做起来,所以项目就搁浅了.9月以来,看各路P2P风声水起,很是热闹:这里分享下我的设计文档,算是抛砖引玉, ...

  8. Codeforces Round #281 (Div. 2) D. Vasya and Chess 水

    D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Windows Live Writer编写Octopress

    Windows live Writer是一个可以用来离线编写,并发布博客的工具. Octopress是一个静态博客生成系统.使用群体多是geek,主要有显示代码清晰,git同步,并且不用购买空间的特点 ...

  10. iOS - OC RunLoop 运行循环/消息循环

    1.RunLoop 1)运行循环: 运行循环在 iOS 开发中几乎不用,但是概念的理解却非常重要. 同一个方法中的代码一般都在同一个运行循环中执行,运行循环监听 UI 界面的修改事件,待本次运行循环结 ...