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

题解:KMP next函数的应用。

#include <cstdio>
#include <cstring>
#include <cstdlib> const int MAXN = ; char table[];
char extable[];
char ori[MAXN];
char aft[MAXN];
int next[MAXN];
int len; void init()
{
for ( int i = ; i < ; ++i )
extable[ table[i]-'a' ] = 'a' + i; len = strlen(ori);
for ( int i = ; i < len/; ++i )
aft[i] = ori[i]; for ( int i = len/; i < len; ++i )
aft[i] = table[ ori[i] - 'a' ]; aft[len] = '\0'; return;
} void getNext( char* s, int* next )
{
int length = len;
int i = , j = -;
next[] = -;
while ( i < length )
{
if ( j == - || s[i] == s[j] )
{
++i, ++j;
next[i] = j;
}
else j = next[j];
}
} int main()
{
int T;
scanf( "%d", &T );
while ( T-- )
{
scanf( "%s", table );
scanf( "%s", ori );
init();
getNext( aft, next ); int ans = len;
//printf("next[%d] = %d\n", ans, next[ans] );
while ( next[ans] > len/ ) ans = next[ans];
ans = len - next[ans];
//printf( "ans = %d\n", ans );
for ( int i = ; i < ans; ++i )
printf( "%c", ori[i] );
for ( int i = ; i < ans; ++i )
printf( "%c", extable[ ori[i] - 'a' ] );
puts("");
}
return ;
}

最新文章

  1. Android开发-之环境的搭建
  2. 几个简单的js正则验证
  3. Oracle 【IT实验室】数据库备份与恢复之一:exp/imp(导出与导入&amp;装库与卸库)
  4. ArcGIS Engine开发之旅10--空间参考及坐标转换
  5. Sublime怎样新建HTML文档
  6. 转:Oracle中的rownum不能使用大于&gt;的问题
  7. Mysql避免全表扫描sql查询优化 .
  8. apache AH01630: client denied by server configuration错误解决方法
  9. Windows命令行命令集锦
  10. 第三节:ThreadPool的线程开启、线程等待、线程池的设置、定时功能
  11. 将汉字转化为拼音的js插件
  12. 在a标签内添加hover样式的方法:
  13. 【转】linux下查看磁盘分区的文件系统格式
  14. Unity3D学习笔记(二十八):Editor
  15. ubuntu下常用命令
  16. Windows网络命令
  17. cropper图片剪裁 , .toBlob()报错
  18. hibernate:inverse、cascade,一对多、多对多详解
  19. 跟着太白老师学python day10 函数嵌套, global , nonlocal
  20. iOS开发基础控件--UIButton

热门文章

  1. React通过dva-model-extend实现 dva 动态生成 model
  2. #leetcode刷题之路12-整数转罗马数字
  3. 微信小程序调用api接口
  4. 端午节佳节从CSDN博客搬家来这,请多多指教
  5. 关于NPOI导出excel文件(xls和xlsx两种格式)提示格式不符的问题
  6. JS 时间格式化,模拟PHP date,时间格式化封装函数
  7. 分享一个强大的makedown编辑器
  8. go基础语法-循环语句
  9. 20145207 ms08_067攻击实验
  10. 优步UBER司机全国各地奖励政策汇总 (3月28日-4月3日)