#include #include #include int N; std::list str; std::list enc; std::list tmp; void encrypt() { std::list::iterator iter; while (!str.empty()) { int mam = str.size(); enc.push_back(str.front()); str.pop_front(); mam--; int x = 0; tmp.clear(); int u; while (mam > 0) { x = (x + mam / N) % mam; iter = str.begin(); for (u = 0; u < x; u++) { iter++; } enc.push_back(*iter); str.erase(iter); mam--; } break; while (!tmp.empty()) { str.push_back(tmp.front()); tmp.pop_front(); } } //unsigned i; for (iter = enc.begin(); iter != enc.end(); iter++) { printf("%c", *iter); } printf("\n"); enc.clear(); str.clear(); } int main() { char c; while (1) { scanf("%d", &N); getchar(); if (N == 0) break; while ((c = getchar()) != '\n') { if (c == ' ') continue; str.push_back(toupper(c)); } encrypt(); } return 0; }