#include <iostream> #include <string> #include <algorithm> using namespace std; char key[11]; char word[11][11]; char str[101]; struct INDEX { int index; bool operator<(const INDEX& o)const { return key[this->index]<key[o.index]; } }index[11]; int main() { freopen("test.txt", "r", stdin); while (cin>>key && strcmp(key, "THEEND")!= 0) { cin>>str; int c = strlen(key); for (int i = 0; i < c; i++) index[i].index = i; stable_sort(index, index+c); int len = strlen(str); int r = len/c; for (int i = 0; i < c; i++) { int pos = index[i].index; for (int j = 0; j < r; j++) { word[j][pos] = str[i*r+j]; } } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { printf("%c", word[i][j]); } } printf("/n"); } return 0; }