Clairewd’s message
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;
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int MS=;
char str1[MS],str2[MS],str3[MS];
int next[MS];
int table[];
void get_next(char *s,int *next)
{
int i=,j=;
next[]=;
int len=strlen(s);
while(i<len)
{
if(j==||s[i-]==s[j-])
{
i++;
j++;
next[i]=j; //求最大循环次数 或者前后公共缀的长度 就用这个
/*
if(s[i-1]==s[j-1])
next[i]=next[j]; //优化了功能却减弱了
else
next[i]=j;
*/
}
else
j=next[j];
}
} int KMP(char *s,char *t,int pos)
{
int i=pos,j=;
int len1=strlen(s);
int len2=strlen(t);
get_next(t,next);
while(i<=len1&&j<=len2)
{
if(j==||s[i-]==t[j-])
{
i++;
j++;
}
else
j=next[j];
}
/*
if(j>len2)
return i-len2-1;
return -1;
*/
return j-;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",str1);
scanf("%s",str2);
int len1=strlen(str1);
int len2=strlen(str2);
for(int i=;i<len1;i++)
{
table[str1[i]-'a']=i;
}
int j=;
for(int i=;i<len2;i++)
{
str3[j++]=table[str2[i]-'a']+'a';
}
str3[j]='\0';
j=KMP(str2,str3,(len2+)/+);
if(j*==len2)
printf("%s\n",str2);
else
{
printf("%s",str2);
int tmp=len2-j;
for(int i=j;i<tmp;i++)
printf("%c",str3[i]);
printf("\n");
}
}
return ;
}
Clairewd’s message的更多相关文章
- hdu------(4300)Clairewd’s message(kmp)
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 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
http://acm.hdu.edu.cn/showproblem.php?pid=4300 很难懂题意.... Clairewd’s message Time Limit: 2000/1000 MS ...
- hdu4300 Clairewd’s message【next数组应用】
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- (KMP 扩展)Clairewd’s message -- hdu -- 4300
http://acm.hdu.edu.cn/showproblem.php?pid=4300 Clairewd’s message Time Limit: 2000/1000 MS (Java/Oth ...
- hdu4300 Clairewd’s message
地址:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目: Clairewd’s message Time Limit: 2000/1000 MS (J ...
- 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)
Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...
- hdu4300 Clairewd’s message 扩展KMP
Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...
随机推荐
- 第一百九十五天 how can I 坚持
晚上回来又肚子疼,拉肚子,咋搞的呢. 小米.华为.感觉虽然现在华为有些许优势,哎,还是不说了,感觉小米手机信号好像有问题. 中午吃的刀削面好像不熟,其实,怎么说呢,像开面馆,做的面顾客都吃不完,很明显 ...
- Kali Linux 安装教程-转
rootoorotor昨天折腾了 Kali Linux 1.0,把大概的配置过程记录下来,希望对想接触或使用Kali Linux的同学有所帮助. 请注意: 1.本文为面向新手的教程,没技术含量,没 ...
- 邮件发送服务AWS SES,Mailgun以及SendCloud(转)
原文:http://www.l4zy.com/posts/aws_ses-mailgun-sendcloud.html 电子邮件这一已经诞生很多年的互联网基础服务并没有随着时间的推移而慢慢消亡,实际上 ...
- express 学习笔记
首先把这个库加载下来 npm install -g express 这样会安装它所有依赖包,这个非常恐怖.这个框架要依赖这么多外来的东西,如果有一个不与时俱进就会拖累整个框架的质量. C:\windo ...
- USB枚举过程(2)
用bus hound 得到的数据 GET MAX LUN 命令 详见USB_MSC_BlukOnly_v1.0 接下来用到的是UFI SCSI
- UI:触摸事件 与 事件的回应
事件分类:晃动.触摸.远程控制(如遥控器.红外控制) 触摸开始时候的方法(判断单击,双击,三击事件可以写在这里) -(void)touchesBegan:(NSSet *)touches withEv ...
- 读写锁:ReadWriteLock
http://my.oschina.net/20076678/blog/173165 一.在JDK文档中关于读写锁的相关说明 ReadWriteLock 维护了一对相关的 锁 ,一个用于只读操作, ...
- C++ assert()断言
assert是一个宏定义,原型定义在<assert.h>中: #include <assert.h> void assert( int expression ); 其作用是:如 ...
- Spring三种实例化Bean的方法
1.实例化bean的三种方法:(1) 构造器<!-- 体验1 --><bean id="personService" class="com.persia ...
- HDU1028 Ignatius and the Princess III 【母函数模板题】
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...