SOJ 1036
来源:互联网 发布:mysql默认配置文件 编辑:程序博客网 时间:2024/06/06 07:29
1036. Crypto Columns
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
BATBOYEYDEMBLRTHANMEKTETOEEOTHHUMDINGEIAAHEBXOIFWEHRXONNAALRSUMNREDEXCTLFTVEXPEDARTAXNAARYIEXTHEEND
Sample Output
MEETMEBYTHEOLDOAKTREENTHONCEUPONATIMEINALANDFARFARAWAYTHERELIVEDTHREEBEARSXXXXXX
很简单的题目,依照题意进行模拟还原即可。// Problem#: 1036// Submission#: 5054968// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include<vector>#include<algorithm>#include<iostream>#include<string>using namespace std;struct node{//UPPER保存keyword的一个字母,num保存这一字母在keyword中的序号 char UPPER; int num; node(char c,int n) { UPPER=c; num=n; }};vector<node> keyword;//将keyword转换成node节点存入容器 char plain[101][101];//用二维数组来保存原文 string cipher,key;//cipher保存密文字符串,key保存keyword字符串 bool cmp(node A,node B)//对keyword的字母进行稳定排序 { if(A.UPPER!=B.UPPER) return A.UPPER<B.UPPER; else return A.num<B.num;}int main(){ while(cin>>key&&key!="THEEND") { keyword.clear(); cin>>cipher; for(int i=0;i<key.size();++i) { keyword.push_back(node(key[i],i+1)); } sort(keyword.begin(),keyword.end(),cmp);//排序后keyword中的字母按字典序排列且相同字母的先后顺序不变 for(int i=0;i<key.size();++i) { for(int j=1;j<=cipher.size()/key.size();++j)//每列的字符数量为 cipher.size()/key.size() { plain[j][keyword[i].num]=cipher[i*cipher.size()/key.size()+j-1];//将每列字符放回原来位置 } } for(int i=1;i<=cipher.size()/key.size();++i)//恢复原状后再按先左右后上下的顺序打印就是原文 { for(int j=1;j<=key.size();++j) { cout<<plain[i][j]; } } cout<<endl; } return 0;}
- SOJ 1036
- soj
- soj 1814
- SOJ-1012
- SOJ-1013
- SOJ-1015
- SOJ-1016
- SOJ-3327
- soj 3109
- { }soj.1206
- { }soj.2013
- SOJ-Dollars
- soj 1715
- soj 1681
- soj 6099
- soj 1050
- SOJ 13984
- SOJ.MyVector
- Nginx+Ftp+Fileinput做图片上传显示服务器(三)
- Java中使用Thread创建多线程并启动
- 信源编码第二章 哈夫曼编码
- 互联网日志分析技术及分析指标
- jQuery学习(三)---基础语法---操作
- SOJ 1036
- 历届试题 趣味算式填符号
- HDU 2899 Strange fuction
- 解决100个进程莫名其妙逐渐挂掉的问题
- HDU1215_七夕节_算数基本定理
- HTTP要点概述:三,客户端和服务器,请求和响应
- 从需求管理到产品开发流程,硅谷产品方法论大揭秘
- 编码问题-python3
- maven 的生命周期