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. c语言中数组相关问题

    c语言中数组相关问题: 1.数组基本定义: 相同数据类型的元素按一定顺序排列的集合,就是把有限个类型相同的变量用一个名字命名,然后用编号区分他们的变量的集合,这个名字称为数组名,编号称为下标.组成数组 ...

  2. C++ Union妙用(将列表初始化用于数组元素)

    Union是个不被注意的关键字,意为联合体,这是个诡异的名字.若不是为了继承C语言,它也不会出现在C++中(虽说,union在C++中得到了扩充,完成了接近类的功能).它的作用主要是节省内存空间,在嵌 ...

  3. UVA 11729 - Commando War(贪心 相邻交换法)

    Commando War There is a war and it doesn't look very promising for your country. Now it's time to ac ...

  4. 字节序转换与结构体位域(bit field)值的读取

    最近又遇到了几年前遇到的问题,标记一下. 对于跨字节位域(bit field)而言,如果数据传输前后环境的字节序不同(LE->BE,BE->LE),简单地调用(ntohs/ntohl/ht ...

  5. AAABBBBCCCC

    语单词词性简写语的意义:,n. 名词 ,noun的缩写v. 动词 , verb的缩写pron. 代词 , pronoun的缩写adj. 形容词, adjective的缩写adv. 副词, adverb ...

  6. PL/SQL学习(三)游标

    原文参考:http://plsql-tutorial.com/ 两种类型:     隐式:         执行INSERT.UPDATE.DELETE 或者只返回一条结果的SELECT语句时默认创建 ...

  7. EncodingUtils 编译不通过

    在Android Studio中开发, 将字符数组转成字符串: Strin re= EncodingUtils.getString(bytes,"UTF-8"); 可是提示Enco ...

  8. python从socket做个websocket的聊天室server

    下面的是server端:把IP改成自己的局域网IP: #coding:utf8 import socket,select import SocketServer import hashlib,base ...

  9. ImageList半透明,Alpha通道bug处理。

    由于ImageList的先天障碍,对alpha通道支持不好.虽然到xp有所改善,但瑕疵依然存在. 通过reflactor发现ImageList通过windows api来进行读写的.写入数据时会对原始 ...

  10. 例行性工作排程 (crontab)

    1. 什么是例行性工作排程 1.1 Linux 工作排程的种类: at, crontab 1.2 Linux 上常见的例行性工作2. 仅运行一次的工作排程 2.1 atd 的启动与 at 运行的方式: ...