4300.Clairewd’s message
来源:互联网 发布:行业数据分析 编辑:程序博客网 时间:2024/05/20 13:04
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6066 Accepted Submission(s): 2276
Problem Description
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.
T<= 100 ;
n<= 100000;
2abcdefghijklmnopqrstuvwxyzabcdabqwertyuiopasdfghjklzxcvbnmqwertabcde
abcdabcdqwertabcdetips:用KMP可以做,但是貌似EKKMP才是正解,不过。。。毕竟才接触KMP,见谅这道题,没啥好说的,先直接输出the intercepted text,且保存其后一半为s2,然后s1用密钥翻译利用s2去匹配s2,这里的KMP需要改一下下#include <iostream>
#include <string.h>
using namespace std;
void Get(char *a,int *next);
int KMP(char *a, char *b,int *next);
int mynext[100005];
char s1[100005],s2[100005],table[26];
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%s%s",table,s1);
printf("%s",s1); //先直接输出intercepted text
int len = (int) strlen(s1);
strcpy(s2,s1 + (len+1)/2); //这里注意是len+1,因为奇数下len/2会使得s2超出原字符一半,会出错。。。因为我就卡在这里。。。无语
for (int n = 0;n < len;n++)
{
for (int m = 0;m < 26;m++)
if (s1[n] == table[m]) {s1[n]='a'+m; break;} //解码
}
Get(s1,mynext);
int tmp = KMP(s2,s1,mynext);
for (int n = tmp;n < len - tmp;n++) printf("%c",s1[n]);
printf("\n");
}
return 0;
}
void Get(char *a,int *next)
{
int len = (int) strlen(a);
int j = 0,k = -1;
mynext[0] = -1;
while (j < len - 1)
{
if (k == -1 || a[j] == a[k])
{
j++;
k++;
if (a[j] != a[k]) mynext[j] = k;
else mynext[j] = mynext[k];
}
else k = mynext[k];
}
return ;
}
int KMP(char *a, char *b,int *next)
{
int len_a,len_b,A,B;
len_a = (int) strlen(a);
len_b = (int) strlen(b);
A=0;
B=0;
while (A < len_a && B < len_b)
{
if (B == -1 || a[A] == b[B])
{
A++;
B++;
if (A == len_a) return B;
}
else
B = mynext[B];
}
return 0;
}
- 4300.Clairewd’s message
- HDU4300:Clairewd’s message
- Clairewd’s message +KMP
- Clairewd’s message (KMP)
- Clairewd’s message
- hdu4300---Clairewd’s message
- hdu4300 Clairewd’s message
- Clairewd’s message
- Clairewd’s message
- HDU4300 Clairewd’s message
- 1002: Clairewd’s message
- Clairewd’s message
- Clairewd’s message
- HDOJ 4300 Clairewd’s message
- 【KMP】 hdu4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- HDU-Clairewd’s message-4300
- 0到1搞一个windows开发环境
- AtomicInteger的并发处理
- windows下的nmake的makefile编写
- 粒子滤波(Particle Filter)及其在机器人定位中的应用
- axios基本用法
- 4300.Clairewd’s message
- Java进阶代码
- 使用转换mnist数据库保存为bmp图片
- 向python脚本传递参数的方法
- cos组件实现文件上传
- 【java】消息队列
- RTSP视频流的远程播放的实现
- HDU2031进制转换
- python Non-ASCII character '\xe5' in file...的问题