#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;
}
Sicily 1036. Crypto Columns
最新推荐文章于 2015-07-11 16:06:00 发布