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

BATBOY
EYDEMBLRTHANMEKTETOEEOTH
HUMDING
EIAAHEBXOIFWEHRXONNAALRSUMNREDEXCTLFTVEXPEDARTAXNAARYIEX
THEEND

Sample Output

MEETMEBYTHEOLDOAKTREENTH
ONCEUPONATIMEINALANDFARFARAWAYTHERELIVEDTHREEBEARSXXXXXX

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

#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std; int main(int argc, char *argv[])
{
string keyWorld;
string message; while (cin >> keyWorld && keyWorld != "THEEND") {
cin >> message; multimap<char, int> keyOrder;
int eachRowNum = keyWorld.size(); for (int i = ; i != eachRowNum; ++i) {
keyOrder.insert(pair<char, int>(keyWorld[i], i));
} int colNum = message.size() / eachRowNum; vector<string> result;
for (int i = ; i != eachRowNum; i++) {
result.push_back(message.substr(i * colNum, colNum));
}
int index = ;
int re[];
for (multimap<char, int>::iterator iter = keyOrder.begin();
iter != keyOrder.end(); ++iter) {
re[iter->second] = index++;
} for (int i = ; i != colNum; ++i) {
for (int j = ; j != eachRowNum; ++j) {
cout << result[re[j]][i];
}
}
cout << endl;
} return ;
}

最新文章

  1. .net 一些开源的东东
  2. js字符串RTrim方法(right trim)
  3. How can I style a JavaFX SplitMenuButton in CSS
  4. 1011 最大公约数GCD
  5. 打开Domion 提示: 管理员ID过期
  6. 亚马逊 在线测试题目 amazon (变种的)三叉树的最近公共祖先问题
  7. 一个用于清除loadrunner产生log文件的批处理
  8. Java学习----日期函数
  9. [转载]Heritrix 提高效率的若干方法
  10. LeetCode OJ 4. Median of Two Sorted Arrays
  11. Asp.Net Core 项目实战之权限管理系统(8) 功能菜单的动态加载
  12. 备忘:有MTU值设置不当导致的部分网站无法访问问题
  13. ansible基本使用教程
  14. Docker学习实践 - Docker安装MySql数据库
  15. Flask中使用数据库连接池 DBUtils ——(4)
  16. OTB数据库上各tracker评测结果
  17. Linux下清理内存和Cache方法见下文:
  18. Android Studio配置文件路径修改
  19. IIS日志存入数据库之二:ETW
  20. $digest already in progress 解决办法

热门文章

  1. 在a标签的href用户#name 的可以实现页面 上下跳转
  2. hdu 1281 棋盘游戏 (二分匹配)
  3. jQuery全选反选实例
  4. [转载]看看大牛们是怎样获得英文综述(reviews)的?
  5. [洛谷P5205]【模板】多项式开根
  6. URAL1297:Palindrome——题解
  7. 一种高效的寻路算法 - B*寻路算法
  8. git使用笔记(十二)stash
  9. G - YYS FZU - 2278 数学期望 (大数)
  10. SQLite 学习笔记