zoukankan      html  css  js  c++  java
  • soj1036. Crypto Columns

    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

    BATBOY
    EYDEMBLRTHANMEKTETOEEOTH
    HUMDING
    EIAAHEBXOIFWEHRXONNAALRSUMNREDEXCTLFTVEXPEDARTAXNAARYIEX
    THEEND

    Sample Output

    MEETMEBYTHEOLDOAKTREENTH
    ONCEUPONATIMEINALANDFARFARAWAYTHERELIVEDTHREEBEARSXXXXXX

    虽然是水题,但是感觉做得好麻烦。

    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    using namespace std;
    char cc[11][11];
    int main()
    {
    	string ss;
    	while(cin >> ss && ss != "THEEND")
    	{
    		int i,j,k;
    		string mima;
    		cin >> mima;
    		vector<char> qq;
    		int coloum = ss.size();
    		int LL = mima.size();
    		int row = LL / coloum;
    		for(i = 0;i < coloum;i++)
    			qq.push_back(ss[i]);
    		sort(qq.begin(),qq.end());
    		for(i = 0;i < coloum;i++)
    		{
    			for(j = 0;j < coloum;j++)
    			{
    				if(qq[i] == ss[j])
    				{
    					for(k = 0;k < row;k++)
    					{
    						cc[k][j] = mima[i*row+k];
    					}
    					ss[j] = ' ';
    					break;
    				}
    			}
    		}
    		for(i = 0;i < row;i++)
    		{
    			for(j = 0;j < coloum;j++)
    			{
    				cout << cc[i][j];
    			}
    		}
    		cout << endl;
    	}
    	return 0;
    }
    					
    
  • 相关阅读:
    Spring整合SpringDataJpa配置文件头
    SpringDataJpa全部依赖
    Spring data jpa persistence .xml 配置文件
    最新为Phpstorm配置xdebug 进行断点调试
    如何根据不同的浏览器写不同的css样式达到兼容
    关于ecshop的那些故事
    安装xampp 后 发现 apache 启动不起来
    关于在biweb 中安装完成后 首页上方报错问题的解决
    phpstormn 中 xdebug 的详细配置2
    关于phpstorm中安装配置xdeug
  • 原文地址:https://www.cnblogs.com/sysu-blackbear/p/3277666.html
Copyright © 2011-2022 走看看