#include <stdio.h>
#include <string.h>
#define N 3
char tower[N][10];
int towerLength;
int isComplete()
{
for (int i = 1; i < N; ++i) {
if (strlen(tower
[i
]) == towerLength
) return 1;
}
return 0;
}
void swap(char *p1, char *p2)
{
int t;
if (t)--t;
p1 += t;
if (t)--t;
p2 += t;
if (*p1 == 0) {
*p1 = *p2;
*p2 = '\0';
return;
}
if (*p2 == 0) {
*p2 = *p1, *p1 = '\0';
return;
}
if (*p1 < *p2) {
*(p2 + 1) = *p1;
*p1 = '\0';
return;
} else {
*(p1 + 1) = *p2;
*p2 = '\0';
return;
}
}
int main(void)
{
int cycle = 0;
scanf("%d",&towerLength
); for (int i = 0; i < N; ++i)
for (int j = 0; j < sizeof(tower) / sizeof(tower[0]); ++j)tower[i][j] = '\0';
for (int i = 0; i < towerLength; ++i) tower[0][i] = '0' + towerLength - i;
while (1) {
swap(tower[(cycle + 1) % N], tower[(cycle + 2) % N]);
++cycle;
cycle %= N;
for (int i
= 0; i
< N
; ++i
)printf("%d:%-12s", i
, tower
[i
]); // for (int i = 0; i < N; ++i)printf("%-12s", tower[i]);
if (isComplete())break;;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2RlZmluZSBOIDMKY2hhciB0b3dlcltOXVsxMF07CmludCB0b3dlckxlbmd0aDsKaW50IGlzQ29tcGxldGUoKQp7CiAgZm9yIChpbnQgaSA9IDE7IGkgPCBOOyArK2kpIHsKICAgIGlmIChzdHJsZW4odG93ZXJbaV0pID09IHRvd2VyTGVuZ3RoKQogICAgICByZXR1cm4gMTsKICB9CiAgcmV0dXJuIDA7Cn0KCnZvaWQgc3dhcChjaGFyICpwMSwgY2hhciAqcDIpCnsKICBpbnQgdDsKICB0ID0gc3RybGVuKHAxKTsKICBpZiAodCktLXQ7CiAgcDEgKz0gdDsKICB0ID0gc3RybGVuKHAyKTsKICBpZiAodCktLXQ7CiAgcDIgKz0gdDsKICBpZiAoKnAxID09IDApIH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