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. getbyclass

    其实以前我偷偷学习正则表达式的时候,写过一个getbyclass的方法,最近翻了翻到处都是错,或者好多重复的,没有用的 代码,于是显得没事我就把这个精简了一下,其实这个方法现在我觉得也是有问题的,问题 ...

  2. Android 内存溢出解决方案(OOM) 整理总结

    在最近做的工程中发现加载的图片太多或图片过大时经常出现OOM问题,找网上资料也提供了很多方法,但自己感觉有点乱,特此,今天在不同型号的三款安卓手机上做了测试,因为有效果也有结果,今天小马就做个详细的总 ...

  3. 从原理上搞定编码-- Base64编码

    BASE64是一种编码方式,通常用于把二进制数据编码为可写的字符形式的数据.这是一种可逆的编码方式.编码后的数据是一个字符串,其中包含的字符为:A-Z.a-z.0-9.+./共64个字符:26 + 2 ...

  4. Highlighting Text Item On Entry In Oracle Forms

    Highlight a Text Item in Oracle Forms With Visual Attribute It is very necessary to highlight the cu ...

  5. tesseract-ocr了解

    安装文件下载地址 http://tesseract-ocr.googlecode.com/files/tesseract-ocr-setup-3.01-1.exe README For the lat ...

  6. ___security_cookie机制,防止栈溢出

    从研究底层和汇编以来,已经多次接触到“栈溢出”这个名词了. 这次在汇编码中看到了个不明就里的 ___security_cookie ,查了下,原来是编译器的安全检查机制.转载一篇文章: 首先,secu ...

  7. 6.mybatis异常:SQL Mapper Configuration,Error parsing Mapper XML,Could not resolve type alias

    在xxxMapper中 <select id="getClazz" parameterType="int" resultType="getCla ...

  8. Redis主从配置详细过程

    Redis的主从复制功能非常强大,一个master可以拥有多个slave,而一个slave又可以拥有多个slave,如此下去,形成了强大的多级服务器集群架构.下面楼主简单的进行一下配置. 1.上面安装 ...

  9. JSP的隐式对象

    JSP支持九个自动定义的变量,江湖人称隐含对象.这九个隐含对象的简介见下表: 参考资料:http://www.runoob.com/jsp/jsp-syntax.html

  10. 初学CDQ分治-NEU1702

    关于CDQ分治,首先需要明白分治的复杂度. T(n) = 2T(n/2)+O(kn), T(n) = O(knlogn) T(n) = 2T(n/2)+O(knlogn), T(n) = O(knlo ...