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. 网站开发常用jQuery插件总结(五)滚动条插件nanoscroller

    网站在展示信息时,如果信息量过大,解决方法主要有三种.1.分页,将信息分页显示.2.整页显示,但是页面过长,影响浏览体验.3.使用滚动条,而默认滚动条样式太单一,用户体验不友好.所以我们需要美化滚动条 ...

  2. 《JavaScript高级程序设计》笔记(3):传递参数

    待更新... 9.17更新: ECMAScript中所有函数的参数都是按值传递的.也就是说,把函数外部复制给函数内部的参数,就和把值从一个变量复制到另一个变量一样.基本类型值的传递如同基本类型变量的复 ...

  3. HTML块

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. 用PHP Session和Javascript实现文件上传进度条,处理进度条

    参考http://www.pureweber.com/article/php-upload-progress/ php显示处理进度条http://blog.csdn.net/boabc2304/art ...

  5. lnmp安装--php与nginx结合

    软件环境: linux:centos5. nginx:.tar.gz php:.tar.gz lnmp与lamp的区别? lnmp(linux+nginx+mysql+php)的提法相对于lamp(l ...

  6. 回答了个问题,9x9 乘法表生成器

    # -*- coding: utf-8 -*- from prettytable import PrettyTable pt = PrettyTable() # 需要安装prettytable这个库来 ...

  7. 用Python实现的一个简单的随机生成器

    朋友在ctr工作,苦于各种排期神马的,让我帮他整一个xxxx管理系统 里面在用户管理上面需要有一个批量从文件导入的功能,我肯定不能用汉字来作唯一性约束,于是想到了随机生成. 我首先想到的是直接用ite ...

  8. Educational Codeforces Round 6 D. Professor GukiZ and Two Arrays

    Professor GukiZ and Two Arrays 题意:两个长度在2000的-1e9~1e9的两个序列a,b(无序);要你最多两次交换元素,使得交换元素后两序列和的差值的绝对值最小:输出这 ...

  9. 关于优化C#程序的五十种方法

    一.用属性代替可访问的字段 1..NET数据绑定只支持数据绑定,使用属性可以获得数据绑定的好处: 2.在属性的get和set访问器重可使用lock添加多线程的支持. 二.readonly(运行时常量) ...

  10. MVC引用CSS文件の正确姿势

    你的css文件目录结构: 将路径写入BundleConfig规则中: using System.Web; using System.Web.Optimization; namespace XXXX { ...