hdu 4300 kmp算法扩展
Clairewd’s message
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2929 Accepted Submission(s): 1132
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<cstring>
#include<cstdio>
using namespace std; int mp[],f[];
char str[],s1[],s2[]; void HalfChange()
{
int i,len=strlen(s1);
for(i=len/;i<len;i++)
s1[i]=str[s1[i]-'a'];
} void getFail()
{
int i,j,len=strlen(s1);
f[]=f[]=;
for(i=;i<len;i++)
{
j=f[i];
while(j && s1[i]!=s1[j]) j=f[j];
f[i+]=(s1[i]==s1[j]?j+:);
}
} int main()
{
int t,i,len,k;
scanf("%d",&t);
while(t--)
{
scanf("%s %s",str,s1);
for(i=;i<;i++) mp[str[i]-'a']=i;
strcpy(s2,s1);
len=strlen(s1);
HalfChange();//把s1后半部分由明文转成密文
getFail();//s1求失配函数
k=f[len];
while(k > len/) k=f[k];
for(i=;i<len-k;i++) printf("%c",s2[i]);
for(i=;i<len-k;i++) printf("%c",mp[s2[i]-'a']+'a');
printf("\n");
}
return ;
}
hdu 4300 kmp算法扩展的更多相关文章
- hdu 3613 KMP算法扩展
Best Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 1711 KMP算法模板题
题意:给你两个串,问你第二个串是从第一个串的什么位置開始全然匹配的? kmp裸题,复杂度O(n+m). 当一个字符串以0为起始下标时.next[i]能够描写叙述为"不为自身的最大首尾反复子串 ...
- hdu 1686 KMP算法
题意: 求子串w在T中出现的次数. kmp算法详解:http://www.cnblogs.com/XDJjy/p/3871045.html #include <iostream> #inc ...
- hdu 4300(kmp)
题意:说实话这个题的题意还真的挺难懂的,我开始看了好久都没看懂,后来百度了下题意才弄懂了,这题的意思就是首先有一个字母的转换表,就是输入的第一行的字符串,就是'a'转成第一个字母,'b'转成转换表的第 ...
- HDU 2594 kmp算法变形
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- KMP算法模板&&扩展
很不错的学习链接:https://blog.csdn.net/v_july_v/article/details/7041827 具体思路就看上面的链接就行了,这里只放几个常用的模板 问题描述: 给出字 ...
- HDU 4333 Revolving Digits 扩展KMP
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意:给以数字字符串,移动最后若干位到最前边,统计得到的数字有多少比原来大,有多少和原来同样,有多少 ...
- 扩展KMP算法
一 问题定义 给定母串S和子串T,定义n为母串S的长度,m为子串T的长度,suffix[i]为第i个字符开始的母串S的后缀子串,extend[i]为suffix[i]与字串T的最长公共前缀长度.求出所 ...
- 扩展KMP算法小记
参考来自<拓展kmp算法总结>:http://blog.csdn.net/dyx404514/article/details/41831947 扩展KMP解决的问题: 定义母串S和子串T, ...
随机推荐
- RabbitMQ Server的安装、配置及常用命令
首先需要安装Erlang环境: http://www.rabbitmq.com/server.html 下载RabbitMQ Server的windows安装包并安装到D盘下: http://www. ...
- mysql grant 用户权限说明
mysql grant 用户权限说明 Mysql 有多个个权限?经常记不住,今天总结一下,看后都能牢牢的记在心里啦!! 很明显总共28个权限:下面是具体的权限介绍:转载的,记录一下: 一.权限表 my ...
- 前端开发面试题之JavaScript(转自公众号)(1)
js基本数据类型:Undefine Number Null Boolean String; js内置对象:数据封装类对象:object.Array.Boolean.String: 其他:Functio ...
- NOIP2016——大家一起实现の物语
由于最近硬盘挂了,换了个固态硬盘,比赛结束后四天一直在装Linux,所以最近一直没怎么更新 看起来挺漂亮的 比赛前一个月申请停了一个月晚自习,在我们这座城市里能做到这种事情已经可以被称为奇迹了,并且在 ...
- java的重载(overload) (2013-10-11-163 写的日志迁移
有以下几点: 1.方法名相同. 2.方法的 参数类型.个数.顺序至少有一项不同. 3.方法的返回类型可以不同. 4.方法的修饰符可以不同. 5.仅返回类型和修饰符不同也不可以构成重载. ----- ...
- golang http 中间件
golang http 中间件 源码链接 golang的http中间件的实现 首先实现一个http的handler接口 type Handler interface { ServeHTTP(Respo ...
- 《linux设备驱动开发详解》笔记——7并发控制
linux中并发无处不在,底层驱动需要考虑. 7.1 并发与竞争 7.1.1 概念 并发:Concurrency,多个执行单元同时.并行执行 竞争:Race Condistions,并发的执行单元对共 ...
- manjaro kde tim QQ
deepin-wine-tim
- SQL语句小练习
一.创建如下表结构(t_book) Id 主键 自增一 bookName 可变长 20 Price 小数 Author 可变长20 bookTypeId 图书类 ...
- nrf51822微信开发入门学习笔记1:开始前的准备
参考:(id:love--baby)https://blog.csdn.net/hunhun1122/article/details/68922493 微信硬件平台:https://iot.weixi ...