// // File: encipher.cc // Author: cteam044 // // Created on October 22, 2011, 2:03 PM // #include #include #include #include char in[10002]; char out[10002]; int step; int lineLen; // // // bool euclid(int x,int y) { int tp; if ( y > x) { tp = x; x = y; y = tp; } while (y != 0){ tp = x % y; x = y; y = tp; } return x != 1; } void compute(){ if ( lineLen <= step){ printf("%s\n", in);return;} // else{ // if (euclid(lineLen, step)) { // printf("sou\n"); // out[lineLen] = 0; // int add = 0; // for (int i = 0; i < lineLen; i++) { // if (i != 0 &&i %(lineLen/step) == 0) add++; // out[(i * step + add) % lineLen] = in[i]; // } // } else { // out[lineLen] = 0; // for (int i = 0; i < lineLen; i++) // out[(i * step) % lineLen] = in[i]; // // // } ////// int top = lineLen/ step + (lineLen % step != 0); int pos = 0; // int chars = lineLen; // int offset = 0; // while(chars > 0) // { // for (int i = offset; i < lineLen; i+=step) // { // out[pos++] = in[i]; // chars--; // } // offset++; // } int top = lineLen / step; if (lineLen%step) top++; for(int i = 0; i = lineLen ) continue; out[pos++] = in[j * top + i]; } } out[lineLen] = 0; printf("%s\n", out); } int main(int argc, char** argv) { while (1){ scanf("%d", &step); while(getchar() != '\n'); if ( step == 0) break; gets(in); //in[strlen(in) - 1] = 0; int pos = 0; lineLen = strlen(in); for (int i = 0; i < lineLen; i ++) { if (in[i] == ' ') {continue;} else in[pos++] = toupper(in[i]); } in[pos] = 0; //printf("%s\n", in); lineLen = strlen(in); compute(); } return (0); }