Title: A string, minus the spaces and symbols to become "plaintext". Another string is called "keyword". The plaintext is lined up in rows, each row has a keyword.size width, and cannot be filled with a column filled with other characters, resulting in a character matrix. Each time you select the column that corresponds to the smallest dictionary order in the keyword, the selected character is no longer selected, and a new string is formed as the output string as the column of the matrix to be selected.
The idea of solving problems: sorting the characters in keyword and their corresponding columns, using sorting results to revert to a character matrix, and then output the character matrix by line.
The code is as follows:
1#include <iostream>2#include <string>3#include <vector>4 using namespacestd;5 6 Const intCOLS = the;7 Const intROWS = the;8 9 stringkw;Ten stringCT; One A CharM[rows][cols]; - - voidinit () { the for(inti =0; i < ROWS; i++) { - for(intj =0; J < COLS; J + +) { -M[I][J] =0; - } + } - } + A structElem { at Charch; - intCol; - }; - - Elem Elems[cols]; - in BOOLcmpConstElem & E1,ConstElem &E2) { - /*if (e1.ch > e2.ch) { to return true; + } else if (e1.ch < e2.ch) { - return false; the } else { * if (E1.col > E2.col) { $ return true;Panax Notoginseng } else if (E1.col < E2.col) { - return false; the } else { + return false; A } the }*/ + - return(e1.ch > e2.ch) | | (e1.ch = = e2.ch && e1.col >e2.col); $ } $ - intMain () { - stringEnd ="theend"; the - while(Cin >> kw, kw! =end) {WuyiCIN >>CT; the intc =kw.size (); - intR = ct.size ()/kw.size (); Wu - for(inti =0; I < C; i++) { Aboutelems[i].ch =Kw[i]; $Elems[i].col =i; - } - - for(inti =0; I < C; i++) { A for(intj =0; J < C-i-1; J + +) { + if(CMP (Elems[j], elems[j +1])) { theElem Elem =Elems[j]; -ELEMS[J] = elems[j+1]; $elems[j+1] =Elem; the } the } the } the - for(inti =0; I < C; i++) { in intBegin = R *i; the //int end = begin + R; the intCol =Elems[i].col; About the for(intj =0; J < R; J + +) { theM[j][col] = Ct[begin +j]; the } + } - the for(inti =0; I < R; i++) {Bayi for(intj =0; J < C; J + +) { thecout <<M[i][j]; the } - } - thecout <<Endl; the } the the return 0; -}
SOJ 1036. Crypto Columns