Clairewd 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.

InputThe first line contains only one integer T, which is the number of test cases.

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.

Hint

Range of test data:

T<= 100 ;

n<= 100000;

OutputFor each test case, output one line contains the shorest possible complete text.Sample Input

2
abcdefghijklmnopqrstuvwxyz
abcdab
qwertyuiopasdfghjklzxcvbnm
qwertabcde

Sample Output

abcdabcd
qwertabcde 题目意思非常绕。。。其实就是给你一个加密表,然后给你一个字符串S, 是由密文+明文构成,但是明文可能不完整。所以可以知道密文>=明文 所以就可以把S翻译一下得到T串。 S的后缀是明文(可能不完整) T的前缀是完整明文。
然后S和T匹配。存在这么一个位置 i+extend[i]>=len&&i>extend[i] 说明满足题意
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=;
int _,Next[maxn],extend[maxn],len;
char table[],S[maxn],T[maxn],temp[]; void getnext() {
Next[]=len;
int j=;
while(j+<len&&T[j]==T[j+]) j++;
Next[]=j;
int k=;
for(int i=;i<len;i++) {
int L=Next[i-k],p=k+Next[k]-;
if(i+L<p+) Next[i]=L;
else {
j=max(,p-i+);
while(i+j<len&&T[i+j]==T[j]) j++;
Next[i]=j;
k=i;
}
}
} void getextend() {
getnext();
int j=;
while(j<len&&T[j]==S[j]) j++;
extend[]=j;
int k=;
for(int i=;i<len;i++) {
int L=Next[i-k],p=k+extend[k]-;
if(i+L<p+) extend[i]=L;
else {
j=max(,p-i+);
while(i+j<len&&S[i+j]==T[j]) j++;
extend[i]=j;
k=i;
}
}
} int main() {
//freopen("in","r",stdin);
for(scanf("%d",&_);_;_--) {
scanf("%s%s",table,S);
len=strlen(S);
for(int i=;i<;i++)
temp[table[i]]='a'+i;
for(int i=;i<len;i++)
T[i]=temp[S[i]];
T[len]='\0';
getextend();
int i;
for(i=;i<len;i++) {
if(i+extend[i]>=len&&i>=extend[i]) break;
}
for(int j=;j<i;j++) printf("%c",S[j]);
for(int j=;j<i;j++) printf("%c",T[j]);
printf("\n");
}
}

kuangbin专题十六 KMP&&扩展KMP HDU4300 Clairewd’s message的更多相关文章

  1. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  2. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  5. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  6. kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  9. kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence

    Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...

随机推荐

  1. jackson 进行json与java对象转换 之三

    2.测试类,没用Junit,用Main()方法输出. package test; import java.io.IOException; import java.util.ArrayList; imp ...

  2. DAY11-MYSQL单表查询

    一 单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 二 关键 ...

  3. python取一个字符串中最多出现次数的词

    #-*- coding:utf-8 -*- #取一个字符串中最多出现次数的词 import re from collections import Counter my_str = "&quo ...

  4. day36-hibernate检索和优化 09-Hibernate中的事务:事务处理

  5. Ros学习——创建ROS消息和ROS服务

    1.rosed rosed 是 rosbash 的一部分.利用它可以直接通过package名来获取到待编辑的文件而无需指定该文件的存储路径了. rosed默认的编辑器是vim.修改其他的,打开~/.b ...

  6. ubuntu16.04 安装caffe2

    1.使用conda创建环境 conda create --name caffe2env python=3.6 ---------------------------------success----- ...

  7. Zbar -- 源码分析

    博客转载自:https://blog.csdn.net/sunflower_boy/article/details/50783179 //Img_scanner.c 文件内 int zbar_scan ...

  8. 解决校园Dr客户端端口占用问题(2)

    win + R -> 输入cmd回车 -> 输入netsh winsock reset重启 -> 好了享受上网的快乐吧骚年

  9. C++ 中 const 使用

    如果你一看见C++中const就脱口而出:“常量!”那只能说明你对c++不甚了解.或者说你太2了. const得一些使用方法与场景如下: 1:const修饰普通变量,全局变量,静态变量 ; ; 变量保 ...

  10. [译]Javascript中的switch语句

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...