Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

The columnar encryption scheme scrambles the letters in a message (or plaintext) using a keyword as illustrated in the following example: Suppose BATBOY is the keyword and our message is MEET ME BY THE OLD OAK TREE. Since the keyword has 6 letters, we write the message (ignoring spacing and punctuation) in a grid with 6 columns, padding with random extra letters as needed:

MEETME
BYTHEO
LDOAKT
REENTH

Here, we've padded the message with NTH. Now the message is printed out by columns, but the columns are printed in the order determined by the letters in the keyword. Since A is the letter of the keyword that comes first in the alphabet, column 2 is printed first. The next letter, B, occurs twice. In the case of a tie like this we print the columns leftmost first, so we print column 1, then column 4. This continues, printing the remaining columns in order 5, 3 and finally 6. So, the order the columns of the grid are printed would be 2, 1, 4, 5, 3, 6, in this case. This output is called the ciphertext, which in this example would be EYDEMBLRTHANMEKTETOEEOTH. Your job will be to recover the plaintext when given the keyword and the ciphertext.

Input

There will be multiple input sets. Each set will be 2 input lines. The first input line will hold the keyword, which will be no longer than 10 characters and will consist of all uppercase letters. The second line will be the ciphertext, which will be no longer than 100 characters and will consist of all uppercase letters. The keyword THEEND indicates end of input, in which case there will be no ciphertext to follow.

Output

For each input set, output one line that contains the plaintext (with any characters that were added for padding). This line should contain no spacing and should be all uppercase letters.

Sample Input

  1. BATBOY
  2. EYDEMBLRTHANMEKTETOEEOTH
  3. HUMDING
  4. EIAAHEBXOIFWEHRXONNAALRSUMNREDEXCTLFTVEXPEDARTAXNAARYIEX
  5. THEEND

Sample Output

  1. MEETMEBYTHEOLDOAKTREENTH
  2. ONCEUPONATIMEINALANDFARFARAWAYTHERELIVEDTHREEBEARSXXXXXX

注意是将已经转换过的序列恢复原状。只需要将原来的转换规则逆向就可以。

  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. string keyWorld;
  10. string message;
  11.  
  12. while (cin >> keyWorld && keyWorld != "THEEND") {
  13. cin >> message;
  14.  
  15. multimap<char, int> keyOrder;
  16. int eachRowNum = keyWorld.size();
  17.  
  18. for (int i = ; i != eachRowNum; ++i) {
  19. keyOrder.insert(pair<char, int>(keyWorld[i], i));
  20. }
  21.  
  22. int colNum = message.size() / eachRowNum;
  23.  
  24. vector<string> result;
  25. for (int i = ; i != eachRowNum; i++) {
  26. result.push_back(message.substr(i * colNum, colNum));
  27. }
  28. int index = ;
  29. int re[];
  30. for (multimap<char, int>::iterator iter = keyOrder.begin();
  31. iter != keyOrder.end(); ++iter) {
  32. re[iter->second] = index++;
  33. }
  34.  
  35. for (int i = ; i != colNum; ++i) {
  36. for (int j = ; j != eachRowNum; ++j) {
  37. cout << result[re[j]][i];
  38. }
  39. }
  40. cout << endl;
  41. }
  42.  
  43. return ;
  44. }

sicily 1036. Crypto Columns的更多相关文章

  1. 1036. Crypto Columns 2016 11 02

    /* 对于题目多读几遍,然后再关键字排序的时候,把对应的数组序号也排序, EYDE    MBLR    THAN    MEKT    ETOE    EOTH        MEETME    B ...

  2. soj1036. Crypto Columns

    1036. Crypto Columns Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description The columnar en ...

  3. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  4. ACM学习

    转:ACM大量习题题库   ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库.   US ...

  5. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  6. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  7. (转载)ACM训练计划,先过一遍基础再按此拼搏吧!!!!

    ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. USACO ht ...

  8. 另一个ACM之路建议

    ACM联系建议 一位高手对我的建议: 一般要做到50行以内的程序不用调试.100行以内的二分钟内调试成功.acm主要是考算法的 ,主要时间是花在思考算法上,不是花在写程序与debug上. 下面给个计划 ...

  9. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

随机推荐

  1. asp.net AES加密跟PHP的一致,将加密的2进制byte[]转换为16进制byte[] 的字符串获得

    <?php class AESUtil { public static function encrypt($input, $key) { $size = mcrypt_get_block_siz ...

  2. LeetCode中二叉树题目总结

    本文仅为博主个人总结,水平有限,欢迎大神指出不妥处. 关于二叉树的相关概念可以参见二叉树的百度百科,或binary tree Wiki. 二叉树结点类的常见定义为: /* Definition for ...

  3. 20165218 2017-2018-1 《Java程序设计》第四周学习总结

    20165218 2017-2018-1 <Java程序设计>第四周学习总结 教材学习内容总结 第五章 子类与继承 子类与父类 通过关键字extands定义子类 class 子类 exta ...

  4. Shell编程语法

    创建shell程序的步骤: 第一步:创建一个脚本文件.sh. 第二步:授予权限使它可以执行chmod u+x .sh 第三步:执行 ./example 或者 sh example 脚本调试:      ...

  5. 四连测Day3

    题目链接:https://pan.baidu.com/s/1_vsHfMI_qO-9IDxmFLkHfg 密码: uza8 T1: 小奥的一笔画,判连通性,查奇偶点即可 #include<ios ...

  6. linux 小技巧

      http://blog.csdn.net/xianjie0318/article/details/75712990 1.按内存从大到小排列进程:  ps -eo "%C : %p : % ...

  7. 手脱ASProtect v1.2(无Stolen Code)

    1.载入PEID ASProtect v1.2 2.载入OD > 01C04200 push 跑跑赛道.0042C001 ; //入口处 C3 retn AA stos byte ptr es: ...

  8. Centos6.5+Python2.7 +ffmpeg+opencv2自动安装脚本

    今天安装opencv折腾了多个小时,为以后安装少走弯路,脚本安装 完整 脚本如下: #! /bin/bash sudo yum install -y gcc g++ gtk+-devel libjpe ...

  9. crontab 定期拉取代码

    * * * * * cd /home/wwwroot/default/lion/ && /usr/bin/git pull origin 5hao >> /tmp/git. ...

  10. X210串口配置与stdio移植

    串口控制器初始化关键步骤 (1)初始化串口的Tx和Rx引脚所对应的GPIO(查原理图可知Rx和Rx分别对应GPA0_1和GPA0_0) (2)GPA0CON(0xE0200000),bit[3:0] ...