#include<cstdio>
#include<vector>
using namespace std;
void make_prog(int cur, int n, vector<int> &q)
{
int i,j;
if (cur == n)
{
for (j = 0; j < n; j++)printf(" ");
printf("writeln(");
for (j = 0; j < n-1; j++)printf("%c,", q[j] + 'a');
printf("%c)\n", q[j] + 'a');
}
else for(j = cur; j >= 0; j--)
{
for(i = 0; i < cur; i++)printf (" ");
if (j < cur)printf("else ");
if (j)
printf("if %c < %c then", q[j-1] + 'a', 'a' + cur);
putchar('\n');
vector<int> new_q(q);
new_q.insert(new_q.begin()+j, cur);
make_prog(cur+1, n, new_q);
}
}
main()
{
int m,n;
scanf("%d", &m);
while (m--)
{
scanf("%d", &n);
puts("program sort(input,output);");
puts("var");
int i;
for ( i = 0; i < n-1; i++)
printf ("%c,", 'a' + i);
printf("%c : integer;\nbegin\n", 'a' + i);
printf(" readln(");
for (i = 0; i < n-1; i++)printf("%c,", 'a' + i);
printf("%c);\n", 'a' + i);
vector<int> q;
q.push_back(0);
make_prog(1, n, q);
printf ("end.\n");
if (m)putchar('\n');
}
return 0;
}
uva110 没有循环的排序程序
最新推荐文章于 2022-02-23 15:02:25 发布