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 坚持
今天去了蟒山,天池,刚去的时候身体有点难受,整天都是那样,回来就好多了,不知道怎么回事. 天池竟然是个人造池,挺大,没有去十三陵,回来都很晚了. 去天池竟然是走的小路,已经关了,不让进,里边玲玲清清的 ...
- KextWizard 的使用方法;以及Kext安装的几种工具下载
a.将你需要安装的Kext拖到非中文的路径中: b.运行该软件,将Kext拖入下图对应的方框里,然后选择位置安装: c.选择修复权限和重建缓存(一个是修复Extra文件夹,一个是修复SLE) Kext ...
- HTML5中script的async属性异步加载JS
HTML5中script的async属性异步加载JS HTML4.01为script标签定义了5个属性: charset 可选.指定src引入代码的字符集,大多数浏览器忽略该值.defer 可 ...
- 一条结合where、group、orderby的linq语法
DataTable dt = (from x in dsResult.Tables[0].AsEnumerable() where DataTrans.CBoolean(x["IsCheck ...
- Javascript(JS)对Cookie的读取、删除、写入操作帮助方法
var CookieUtils = { get: function (name) { var cookieName = encodeURIComponent(name) + '=', cookieSt ...
- 【转】解决Fragment already active方法
http://blog.csdn.net/u011730649/article/details/43227721 今天在项目中使用Fragment的时候出现这样的错误: 01-28 10:53:34. ...
- uva10327 - Flip Sort
Flip Sort Sorting in computer science is an important part. Almost every problem can be solved effec ...
- html的下拉框的几个基本使用方法
尽管使用EXT开发了一段时间,可是自己认为我对javascript还是不是非常熟,所以边看书边做小样例 给自己以后用到的时候查看下,都是非常主要的东西,对刚開始学习的人可能有点帮助 以下是代码 < ...
- 怎样解决VirtrualBox不能新建64bit的系统的问题
假设你的VirtrualBox不能新建64bit的虚拟机一般有以下两个原因: 1.电脑是32位的,不支持创建64bit的虚拟机 2.电脑不支持Intel VT-x,或者是Intel VT-x没有打开 ...
- 10分钟学会基于ASP.NET的 JQuery实例 (转)
本文介绍如何在ASP.NET(ASP.NET/AJAX)里使用基于JQuery的AJAX技术.(源代码下载见最后) 在使用JQuery前,请到www.jquery.com下载最新版本的js代码,然后再 ...