(KMP 扩展)Clairewd’s message -- hdu -- 4300
http://acm.hdu.edu.cn/showproblem.php?pid=4300
Clairewd’s message
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4411 Accepted Submission(s): 1676
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;
代码1:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std; #define N 200005 int Next[N];
char s1[N], s2[N];
char a[N], b[N]; void FindNext(char S[])
{
int Slen = strlen(S);
int i=, j=-;
Next[] = -; while(i<Slen)
{
if(j==- || S[i]==S[j])
Next[++i] = ++j;
else
j = Next[j];
}
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%s%s", s1, s2); int len=strlen(s2), i, L;
L = (len+)/; memset(a, , sizeof(a));
memset(b, , sizeof(b)); for(i=; i<; i++)
a[s1[i]-'a'] = 'a'+i;
for(i=; i<L; i++)
b[i] = a[s2[i]-'a'];
b[i] = '*';
b[i+] = '\0';
strcat(b, s2+L); FindNext(b); L = len - Next[len+]; for(i=; i<L; i++)
printf("%c", s2[i]);
for(i=; i<L; i++)
printf("%c", a[s2[i]-'a']);
printf("\n");
}
return ;
}
代码2:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm> using namespace std; const int maxn = ; int Next[maxn];
char s[maxn], a[maxn], pass[maxn]; void FindNext(char S[])
{
int i=, j=-;
Next[] = -; int Slen = strlen(S); while(i<Slen)
{
if(j==- || S[i]==S[j])
Next[++i] = ++j;
else j = Next[j];
}
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int i, len, L;
scanf("%s%s", s, a);
len = strlen(a);
L = (len+)/; for(i=; s[i]; i++)
pass[s[i]-'a'] = i + 'a'; for(i=; i<L; i++)
s[i] = pass[a[i]-'a'];
s[i] = '*';
s[i+] = ; strcat(s, a+i); FindNext(s); L = len - Next[len+]; for(i=; i<L; i++)
{
s[i] = a[i];
s[i+L] = pass[ a[i]-'a' ];
}
s[i+L] = ; printf("%s\n", s);
} return ;
}
(KMP 扩展)Clairewd’s message -- hdu -- 4300的更多相关文章
- J - Clairewd’s message HDU - 4300(扩展kmp)
题目链接:https://cn.vjudge.net/contest/276379#problem/J 感觉讲的很好的一篇博客:https://subetter.com/articles/extend ...
- Clairewd’s message - HDU 4300(next[]运用)
题目大意:给两个串第一个串是翻译表(密文可以通过翻译表翻译成明文),第二个串是由密文+明文组成,前面是密文(完整的),后面是明文(未必完整),问能不能把第二个串补全,输出最短的一种可能. 分析:题 ...
- kuangbin专题十六 KMP&&扩展KMP HDU4300 Clairewd’s message
Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...
- 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)
HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...
- hdu 4300 kmp算法扩展
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 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)
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu4300 Clairewd’s message
地址:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目: Clairewd’s message Time Limit: 2000/1000 MS (J ...
随机推荐
- dstat 性能监测工具
dstat 是一个可以取代vmstat,iostat,netstat和ifstat这些命令的多功能产品.dstat克服了这些命令的局限并增加了一些另外的功能,增加了监控项,也变得更灵活了.dstat可 ...
- How to Pronounce ‘to the’ in a Sentence
How to Pronounce ‘to the’ in a Sentence Share Tweet Share Tagged With: The Word THE, TO Reduction St ...
- servlet类第二篇
1servlet的生命周期是什么? 服务器启动时(web.xml中配置load-on-startup=1,默认为0)或者第一次请求该servlet时,就会初始化一个Servlet对象,也就是会执行初始 ...
- oracle老是出现监听错误
解决方法之一: 点击开始-->选择程序--->选中你安装的oracle版本-->选中配置与移植工具-->选中Net Configuration Assistant-->在 ...
- 吴裕雄 数据挖掘与分析案例实战(8)——Logistic回归分类模型
import numpy as npimport pandas as pdimport matplotlib.pyplot as plt # 自定义绘制ks曲线的函数def plot_ks(y_tes ...
- Flexvolume
https://kubernetes.io/docs/concepts/storage/volumes/ https://github.com/kubernetes/community/blob/ma ...
- springmvc处理url请求步骤
处理步骤: 1.调用DispatcherServlet的doService方法 2.进入DispatchServlet的doDispatch方法 3.进入DispatchServlet的getHand ...
- 将2020年交期的PR回写出来了
OUT_pr表中的交期为2020年和2019年,不应该 回写的PR却回写出来了 优化如下:
- 禁止直接访问ashx页面
if (context.Request.ServerVariables["HTTP_REFERER"] == null) { ...
- 两台Linux之间传文件
安装sudo apt-get install openssh-client openssh-server 使用scp命令: scp john@~/hallo.h /usr/include 将左边移动到 ...