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 坚持
下午去打了会篮球,好累,又把android开发环境搭建起来了,明天把天气应用搞起来. 今天老妈打电话说昨晚梦到我小时候了.. 是啊,都这么大了,不能让他们老操心了. 过两天买根鱼竿去钓鱼. 睡觉.
- 2013 ACM/ICPC南京邀请赛B题(求割点扩展)
题目链接:http://icpc.njust.edu.cn/Contest/194/Problem/B B - TWO NODES 时间限制: 10000 MS 内存限制: 65535 KB 问题描述 ...
- C++的双冒号(域解析符)
在C++中,“::”表示“作用域标识符”或者叫“作用域分解运算符”,比如:“类名::函数名”,这样是表示该函数是该类的成员函数, 但是象下面这种写法:“::函数名”,作用域标识符前面没有任何对象,代表 ...
- LightOJ 1245 Harmonic Number (II)(找规律)
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS ...
- ThinkPad X220i 安装 Mac OSX
联想笔记本是安装黑苹果相对比较容易的~~ ThinkPad X220i配置 型号:ThinkPad X220i CPU: i3 内存:4G 显卡:HD3000 其他: X220i的通用硬件 确认以 ...
- HDU3874Necklace(树状数组+离线操作)
此题的大意思说有一串珠子,每个珠子都有自己的欣赏值value,现在给你一串珠子每个的欣赏值,并给出一些询问,查询某个区间内部总欣赏值是多少,但是有一个约定就是如果这个区间内部有两个珠子的欣赏值是一样的 ...
- HeapAlloc、GlobalAlloc和new等内存分配有什么区别么?
查找了一些 new , GlobalAlloc, HeapAlloc分配内存方式的区别. 转了一些资料 //============================================== ...
- poj1584
题意:已知一个多边形的n个顶点坐标,然后再给一个钉子,给定钉子的半径和圆心坐标,首先判断多边形是否为凸多边形,若为凸多边形,再判断钉子是否可以放到凸多边形内部. 思路: 1.由于顶点给出的顺序可能为逆 ...
- Unity3d:Unknown type 'System.Collections.Generic.CollectionDebuggerView'1
问题描述:如图,在调试状态下说:Unknown type 'System.Collections.Generic.CollectionDebuggerView'1<ignore_js_op> ...
- zookeeper的安装和启动
最近的手上一个项目要用到dubbo,顺便研究下zookeeper 1.下载 下载地址:http://www.apache.org/dyn/closer.cgi/zookeeper/,下载解压到D:\t ...