// @BEGIN_OF_SOURCE_CODE /* @JUDGE_ID: 17243NT 110 C++ "" */ // Send to judge@uva.es #include #include #include #include #ifdef ONLINE_JUDGE #define ins cin #define outs cout #else #define ins fin #define outs fout ifstream fin("myprog.in"); ofstream fout("myprog.out"); #endif int n; char str[10]; void indent(int k) { for(int i = 0; i < k; i++) outs << " "; } void recursion(int k) { char c = 'a' + k; int i, j; str[k] = c; for(i = k; i > 0; i--) { indent(k); if(i < k) outs << "else "; outs << "if " << str[i - 1] << " < " << c << " then\n"; if(k < n - 1) { char temp[10]; strcpy(temp, str); recursion(k + 1); strcpy(str, temp); } else { indent(k + 1); outs << "writeln("; for(j = 0; j < k; j++) outs << str[j] << ","; outs << str[j] << ")\n"; } if(i == 1) { indent(k); outs << "else" << endl; } char t = str[i]; str[i] = str[i - 1]; str[i - 1] = t; } if(k < n - 1) { char temp[10]; strcpy(temp, str); recursion(k + 1); strcpy(str, temp); } else { indent(k + 1); outs << "writeln("; for(j = 0; j < k; j++) outs << str[j] << ","; outs << str[j] << ")\n"; } } int main() { int i, j, nblocks; ins >> nblocks; for(j = 0; j < nblocks; j++) { ins >> n; if(j > 0) outs << endl; outs << "program sort(input,output);\n"; outs << "var\n"; for(i = 0; i < n - 1; i++) outs << (char) (i + 'a') << ","; outs << (char) (i + 'a') << " : integer;\n"; outs << "begin\n"; outs << " readln("; for(i = 0; i < n - 1; i++) outs << (char) (i + 'a') << ","; outs << (char) (i + 'a') << ");\n"; recursion(0); outs << "end.\n"; } return 0; } // @END_OF_SOURCE_CODE