Sicily 1036. Crypto Columns

来源:互联网 发布:linux apache 配置php 编辑:程序博客网 时间:2024/06/05 17:04
#include <iostream>#include <string>using namespace std;void sort_alp(string &text, int index[]){int min;int i, k = 0;char alp;int visited[10] = { 0 };int times = text.length();while (times--) {alp = '[';for (i = 0; i < text.length(); ++i) {if (visited[i] == 0) {if (text[i] < alp) {alp = text[i];min = i;}}}visited[min] = 1;index[k++] = min;}}int main() {string keyword;string ciphertext;char result[10][10];int row;int col;while (cin >> keyword && keyword != "THEEND") {int sorted[10] = {-1};cin >> ciphertext;sort_alp(keyword, sorted);col = keyword.length();row = ciphertext.length() / col;int read;int i, j, k = 0;for (i = 0; i < col; ++i) {read = sorted[i];for (j = 0; j < row; ++j) {result[j][read] = ciphertext[k++];}}for (i = 0; i < row; ++i) {for (j = 0; j < col; ++j) {cout << result[i][j];}}cout << endl;}return 0;}

0 0
原创粉丝点击