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. javascript 获取url参数

    /** window.location.search获取url地址?以后的值 获取url参数有两种方法,第一种如下,第二种是通过正则 */ //基本版 function getParam() { va ...

  2. PAT_1007 素数对猜想

    今天想更的那道题现在还没A出来.先把下午做的一道题更新了吧.快零点了.无奈啊. 问题描述: 让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数.显然有 d1=1 且对于n&g ...

  3. Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)

    Crack Mathmen TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Since mathmen take security ...

  4. ASP.NET中的验证控件

    ASP.NET提供了如下的控件: RequiredFieldValidator: 字段必填 (ControlTovalidate设定要验证的控件) RangeValidator: 值在给定的最大值,最 ...

  5. jquery 去掉重复项(splice,apply,push)

    /* js数组去掉重复项 var somearray = [1,1,2,2,3,3,4,4,'1']; somearray.check(); //somearray will return arr=[ ...

  6. 高效的VS调试技巧

    本文总结了十个调试技巧,当你使用VS的时候可以节省你很多时间. 1.悬停鼠标查看表达式 调试有时候很有挑战性,当你步入一个函数想看看哪块出错的时候,查看调用栈来想想值是从哪来的.另一些情况下,则需要添 ...

  7. MySQL - “Timeout error occurred trying to start MySQL Daemon”解决方法

    前几天,网站出现Many connections的问题,进入mysql,show full processlist发现有154个进程,晕....直接service mysqld restart 但是不 ...

  8. 服务器返回的JSON字符串

    异步请求将type设为"json",或者利 用$.getJSON()方法获得服务器返回,那么就不需要eval()方法,因为这时候得到的结果已经是json对象

  9. Python的面向对象3

    接下来,我们接着讲Python的面向对象,在上一次的博客中,我们详细介绍了类与对象的属性,今天,我们来详细介绍一下面向对象中的方法! 1.定义实例方法 一个实例的私有属性就是以__开头的属性,无法被外 ...

  10. 10g和11g,优化器对外连接的处理对比

    我反省,今天面试有个问题没有说清楚.我给出的结论(而且这个结论我验证过)是:不要使用不必要的外连接,举了下面这个例子却没有说清楚.虽然最近感冒,状态不是很好,但最擅长的东西都没有表达清楚,泪流满面啊: ...