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): 2839    Accepted Submission(s): 1096

Problem Description
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.
 
Input
The 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;

 
Output
For each test case, output one line contains the shorest possible complete text.
 
Sample Input
2 abcdefghijklmnopqrstuvwxyz abcdab qwertyuiopasdfghjklzxcvbnm qwertabcde
 
Sample Output
abcdabcd qwertabcde
 
Author
BUPT
 一个wa的代码,但测试数据都过了。。。。。。。
#include<stdio.h>
#include<string.h>
int next[];
char s[],t[];
void getnext()
{
int i=,j=-;
next[]=-;
int len=strlen(s);
while(i<len)
{
if(s[i]==s[j]||j==-)
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
}
int kmp()
{
int i=,j=;
int lens=strlen(s);
int lent=strlen(t);
while(i<lent&&j<lens)
{
if(s[j]==t[i]||j==-)
{
i++;
j++;
if(i==lent)
return j;
}
else
j=next[j];
}
return ;
}
int main()
{
int n,i,flag,j;
char str[],s1[];
scanf("%d",&n);
while(n--)
{
scanf("%s",str);
scanf("%s",s1);
int len=strlen(s1);
strcpy(t,s1+(len+)/);
printf("%s",s1);
for(i = ; s1[i]; i++)
{
for( j = ; j<; j++)
{
if(s1[i] == str[j])
{
s[i] = 'a'+j;
break;
}
}
}
getnext();
flag=kmp();
for(i=flag;i<len-flag;i++)
printf("%c",s[i]);
printf("\n");
}
return ;
}

ac。。。。。。。。

 #include <stdio.h>
#include <string.h>
int next[];
char str[];
char s1[],s2[]; void getnext(char *t)
{
int i = ,j = -;
next[] = -;
while(t[i])
{
if(j == - || t[i] == t[j])
{
i++;
j++;
next[i] = j;
}
else
j = next[j];
}
} int kmp(char *s,char *t)
{
int i = ,j = ;
int slen =strlen(s),tlen = strlen(t);
getnext(t);
while(i<slen && j<tlen)
{
if(j == - || s[i] == t[j])
{
i++;
j++;
if(i == slen)
return j;
}
else
j = next[j];
}
return ;
} int main()
{
int t,i,flag,j;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
scanf("%s",s1);
int len = strlen(s1);
strcpy(s2,s1+(len+)/);
printf("%s",s1);
for(i = ; s1[i]; i++)
{
for( j = ; j<; j++)
{
if(s1[i] == str[j])
{
s1[i] = 'a'+j;
break;
}
}
} flag = kmp(s2,s1);
// puts(s2);puts(s1);
// printf("%d",flag);
for( i = flag; i<len-flag; i++)
{
printf("%c",s1[i]);
}
printf("\n");
} return ;
}

HDU-4300 Clairewd’s message的更多相关文章

  1. hdu 4300 Clairewd’s message KMP应用

    Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前 ...

  2. hdu 4300 Clairewd’s message 字符串哈希

    Clairewd’s message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU - 4300 Clairewd’s message (拓展kmp)

    HDU - 4300 题意:这个题目好难读懂,,先给你一个字母的转换表,然后给你一个字符串密文+明文,密文一定是全的,但明文不一定是全的,求最短的密文和解密后的明文: 题解:由于密文一定是全的,所以他 ...

  4. hdu 4300 Clairewd’s message(具体解释,扩展KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...

  5. hdu 4300 Clairewd’s message(扩展kmp)

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  6. HDU 4300 Clairewd’s message(KMP+思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从 ...

  7. 【HDU 4300 Clairewd’s message】

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  8. HDU 4300 Clairewd’s message(扩展KMP)

    思路:extend[i]表示原串以第i開始与模式串的前缀的最长匹配.经过O(n)的枚举,我们能够得到,若extend[i]+i=len且i>=extend[i]时,表示t即为该点之前的串,c即为 ...

  9. HDU 4300 Clairewd’s message(扩展KMP)题解

    题意:先给你一个密码本,再给你一串字符串,字符串前面是密文,后面是明文(明文可能不完成整),也就是说这个字符串由一个完整的密文和可能不完整的该密文的明文组成,要你找出最短的密文+明文. 思路:我们把字 ...

  10. HDU 4300 Clairewd’s message (next函数的应用)

    题意:给你一个明文对密文的字母表,在给你一段截获信息,截获信息前半段是密文,后半段是明文,但不清楚它们的分界点在哪里,密文一定是完整的,明文可能是残缺的,求完整的信息串(即完整的密文+明文串). 题解 ...

随机推荐

  1. node.js 小爬虫 imooc 2016.03.06

    爬虫目标:获取http://www.imooc.com/learn/348网页中的章节标题和视频信息. var http = require('http'); var cheerio = requir ...

  2. 10.08_逛逛OSC

    (1)每天逛逛OSC是我的习惯了. JNative.JACOB.Shrinkwrap  API? .Lua.WSO2 Identity Server .JBoss Forge.Bugzilla.Cou ...

  3. 解决UIScrollView 的点击事件

    目前有两种方法 第一种 通过 Category 扩展 UIScrollView 对象,添加触摸事件,(不建议,后续扩展不方便)代码如下 @implementation UIScrollView (Ex ...

  4. linux下shell编程示例-获取进程id

    今天初步学习了一下linux下的shell编程,简单记录一下测试用例 1.编辑shell脚本文件如下: #!/bin/bashecho "hello bash linux"echo ...

  5. php中浮点数计算问题

    如果用php的+-*/计算浮点数的时候,可能会遇到一些计算结果错误的问题,比如echo intval( 0.58*100 );会打印57,而不是58,这个其实是计算机底层二进制无法精确表示浮点数的一个 ...

  6. VMware Workstation 10.0 下载 – 正版序列号+简体中文官方原版

    1.https://download3.vmware.com/software/wkst/file/VMware-workstation-full-10.0.0-1295980.exe 2.https ...

  7. odoo 清除所有运行数据

    测试odoo,如果需要一个干净的db.经常需要清除掉所有业务数据.做如下操作,较为方便 1:建立一个服务器动作,动作的python代码入下. 然后新建一个菜单,菜单动作关联到 这个动作.需要清空db, ...

  8. Python 手册(一)

    Python 手册 Guido van Rossum Fred L. Drake,  Jr., editor PythonLabs Email: python-docs@python.org Rele ...

  9. 在后台代码中引入XAML的方法

    本文将介绍三种方法用于在后台代码中动态加载XAML,其中有两种方法是加载已存在的XAML文件,一种方法是将包含XAML代码的字符串转换为WPF的对象. 一.在资源字典中载入项目内嵌资源中的XAML文件 ...

  10. iOS 9适配技巧

    中文快速导航: 1.iOS9网络适配_ATS:改用更安全的HTTPS(见Demo1) i. WHAT(什么是SSL/TLS?跟HTTP和HTTPS有什么关系) ii. WHY(以前的HTTP不是也能用 ...