hdu------(4300)Clairewd’s message(kmp)
Clairewd’s message
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3433 Accepted Submission(s): 1334
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
Source
2012 Multi-University Training Contest 1
大意: 首先给你一个暗纹表,然后第二行给你一个包含暗纹和名文的的字符串,要你解析出明文... (很屌炸天的英文描述,完全不知道要表达什么,从去年就想做这道题,一看,不明白题意思就放下了...)
代码:
1 #include<cstring>
2 #include<cstdio>
3 #include<map>
4 using namespace std;
5 const int maxn=100005;
6 char stdch[28]; //给出的暗文标准版
7 map<char,int>str;
8 char text[maxn];
9 char tes[maxn];
10 int next[maxn];
11 void getnext(int len){
12 int i=0,j=-1;
13 //memset(next,0,sizeof(next));
14 next[0]=-1;
15 while(i<len){
16 if(j==-1||tes[i]==tes[j]){
17 i++;
18 j++;
19 // next[i]=j; 优化一下
20 if(tes[i]!=tes[j]) next[i]=j;
21 else next[i]=next[j];
22 }
23 else j=next[j];
24 }
25 }
26 void kmp(int len){
27
28 //前半部是暗纹,后半部是明文,所以起点:i
29 //tes是经过翻转之后的暗纹,也就是明文
30 getnext(len);
31 int len1=len;
32 if(len1&1)len1++; //这里需要特别注意因为暗纹要不明文长,明文可以又缺失
33 int i=len1>>1,j=0;
34 while(i<len&&j<len){
35 if(j==-1||text[i]==tes[j]){
36 i++;
37 j++;
38 }
39 else j=next[j];
40 }
41 printf("%s",text);
42 if(j*2!=len) {
43 for(int i=j;i+j<len;i++)
44 printf("%c",tes[i]);
45 }
46 puts("");
47 }
48 int main(){
49 int test;
50 //freopen("test.in","r",stdin);
51 scanf("%d",&test);
52 while(test--) {
53
54 if(!str.empty()) str.clear();
55 scanf("%s",stdch);
56 for(int i=0;i<26;i++)
57 str[stdch[i]]=i;
58 scanf("%s",text);
59 int tslen=strlen(text);
60 for(int i=0;i<tslen;i++){
61 tes[i]=str[text[i]]+'a'; //经过两次旋转
62 }
63 kmp(tslen);
64 }
65 return 0;
66 }
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 用二叉树实现自动求导(Python版)
- 上海展盟网络科技有限公司的 gamebox 组件注入进程导致软件崩溃
- IdentityServer4 3.1.x 迁移到 4.x
- 淘宝用户行为数据分析
- PyTorch中Transformer模型的搭建
- A轮公司数据分析面试经验
- Pytorch转NCNN的流程记录
- 算法图解:如何找出栈中的最小值?
- 滴滴出行二面笔试题
- spring JdbcTemplate 查询,参数中使用BeanPropertyRowMapper的作用
- 百万级类别的分类模型的拆分训练
- 关于Spring定义的preDestroy修饰的方法不执行,有以下两种原因,总有一款适合你
- CSP201912-2-回收站选址题目解析-Java ,
- Spring boot框架快速入门
- SpringBoot 跨域问题:Access to XMLHttpRequest at ‘***‘ from origin ‘***‘ has been blocked by CORS policy