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. 【转载】如何系统地自学 Python?

    原文:如何系统地自学 Python? 作者:彭猫 本文由 知乎 彭猫 授权发布,版权所有归作者,转载请联系作者! 是否非常想学好 Python,一方面被琐事纠缠,一直没能动手,另一方面,担心学习成本太 ...

  2. gitlab配置和搭建 ssh

    (1)查看自己之前是否生成过ssh密钥: cat ~/.ssh/id_rsa.pub 如果出现一段ssh-rsa开头的,表示已经生成了,可以跳过此步骤: (2)如果之前没有生成ssh密钥,使用命令: ...

  3. Hibernate+Struts2+jsp 修改用户信息

    在用户列表页面点击修改,进入修改页面 修改薪酬为555,点击提交,重新跳回该页面 修改成功 关键代码如下 基层的代码,这里增加了一个根据用户id查询的方法 dao层 //修改 public USer ...

  4. 折半查找&clock函数

    #include <stdio.h>#include <time.h> #define CLOCKS_PER_SEC ((clock_t)1000) int binsearch ...

  5. iOS - Swift NSProcessInfo 系统进程信息

    前言 public class NSProcessInfo : NSObject 1.获取系统进程信息 // 创建系统进程信息对象 let processInfo:NSProcessInfo = NS ...

  6. Redis基础知识之—— 缓存应用场景

    转载原文:http://www.cnblogs.com/jinshengzhi/articles/5225718.html 一.MySql+Memcached架构的问题 Memcached采用客户端- ...

  7. CentOS6下yum下载的包存放路径

    http://showerlee.blog.51cto.com/2047005/1169818 yum下载下来的文件保存默认路径是: /var/cache/yum 修改yum配置文件 /etc/yum ...

  8. [转载] 理解 rto

    原文: http://mp.weixin.qq.com/s?__biz=MzAxNjM3MDkyOQ==&mid=204656491&idx=1&sn=5046aa16eee0 ...

  9. poj2208Pyramids(四面体面积--公式)

    链接 一公式题.. 证明讲解参照http://www.cnblogs.com/dgsrz/articles/2590309.html 注意对棱 顺序 #include <iostream> ...

  10. Java JDBC连接数据库 Access连接数据库

    1.加载JDBC驱动程序:  在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机),再通过java.lang.Class类的静态方法forName(String  classN ...