hdu------(4300)Clairewd’s message(kmp)
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
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.
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.
Range of test data:
T<= 100 ;
n<= 100000;
abcdefghijklmnopqrstuvwxyz
abcdab
qwertyuiopasdfghjklzxcvbnm
qwertabcde
qwertabcde
#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)的更多相关文章
- hdu 4300 Clairewd’s message KMP应用
Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...
- HDU 4300 Clairewd’s message(KMP+思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...
- HDU - 4300 Clairewd’s message (拓展kmp)
HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...
- hdu 4300 Clairewd’s message 字符串哈希
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4300 Clairewd’s message(具体解释,扩展KMP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...
- hdu 4300 Clairewd’s message(扩展kmp)
Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...
- hdu 4300 Clairewd’s message(kmp/扩展kmp)
题意:真难懂.. 给出26个英文字母的加密表,明文中的'a'会转为加密表中的第一个字母,'b'转为第二个,...依次类推. 然后第二行是一个字符串(str1),形式是密文+明文,其中密文一定完整,而明 ...
- HDU 4300 Clairewd's message ( 拓展KMP )
题意 : 给你一个包含26个小写字母的明文密文转换信息字符串str,第一个表示'a'对应的密文是str[0].'b'对应str[1]……以此类推.接下来一行给你一个另一个字符串,这个字符串由密文+明文 ...
- HDU 4300 Clairewd’s message(扩展KMP)
思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...
- HDU 4300 Clairewd’s message(扩展KMP)题解
题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...
随机推荐
- ORACLE分页SQL语句
.根据ROWID来分 select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select r ...
- C#四则运算之策略模式
Calculator.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- mybatis的基本配置:实体类、配置文件、映射文件、工具类 、mapper接口
搭建项目 一:lib(关于框架的jar包和数据库驱动的jar包) 1,第一步:先把mybatis的核心类库放进lib里
- SQL collate
摘自:http://www.cnblogs.com/window5549-accp/archive/2009/10/03/1577682.html 我们在create table时经常会碰到这样的语句 ...
- 1----lua的环境搭建
本人使用的是LDT用来学习lua,原因是因为本人熟悉Eclipse的操作,并且安装方便 首先需要下载并配置JDK,也就是java的运行环境(以下为官网网址) http://www.oracle.com ...
- table布局注意点
1.同行等高. 2.宽度自动调节(table-layout:fixed;). 3.处理垂直居中又是神器 参考链接: http://www.blueidea.com/tech/web/2008/6257 ...
- php xml 操作。
参考 文章:http://www.cnblogs.com/zcy_soft/archive/2011/01/26/1945482.html DOMDocument相关的内容. 属性: Attribut ...
- Spring + JDBC 组合开发集成步骤
1:配置数据源,如: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="h ...
- iOS - OC NSSet 集合
前言 NSSet:集合 @interface NSSet<__covariant ObjectType> : NSObject <NSCopying, NSMutableCopyin ...
- iOS - AudioServicesPlay 短频音效播放
前言 extern void AudioServicesPlayAlertSound(SystemSoundID inSystemSoundID) __OSX_AVAILABLE_STARTING(_ ...