#include<stdio.h>
#include<string.h>
int block[30][30];
int ptop[30];
void backtoini(int line, int from, int to);
void print(int);
int main()
{
//
freopen("input.txt", "r", stdin);
int nump;
scanf("%d", &nump);
int from, to;
char ope1[5];
char ope2[5];
memset(block, 0, sizeof(block) );
memset(ptop, 0, sizeof(ptop) );
for(int i = 0; i < nump;i++)
{
block[i][0] = i;
ptop[i] ++;
}
while(scanf("%s %d %s %d", ope1, &from, ope2, &to) == 4)
{
if(!strcmp(ope1,"quit") ) break;
if(from == to) continue;
int scr[2];
int dest[2];
for(int i = 0; i < nump; i++)
{
for(int j = 0; j < ptop[i]; j++)
{
if(block[i][j] == from)
{
scr[0] = i;
scr[1] = j;
}
if(block[i][j] == to)
{
dest[0] = i;
dest[1] = j;
}
}
}
if(scr[0] == dest[0]) continue;
if(!strcmp("move",ope1) && !strcmp("onto",ope2) )
{
backtoini(scr[0], scr[1]+1, ptop[scr[0]]-1);
backtoini(dest[0], dest[1]+1, ptop[dest[0]]-1);
block[dest[0]][ptop[dest[0]]++] = block[scr[0]][--ptop[scr[0]]];
}
if(!strcmp("move", ope1) && !strcmp("over",ope2) )
{
backtoini(scr[0], scr[1]+1, ptop[scr[0]]-1);
block[dest[0]][ptop[dest[0]]++] = block[scr[0]][--ptop[scr[0]]];
}
if(!strcmp("pile", ope1) && !strcmp("onto", ope2))
{
backtoini(dest[0], dest[1]+1, ptop[dest[0]]-1);
for(int i = scr[1]; i < ptop[scr[0]]; i++)
{
block[dest[0]][ptop[dest[0]]++] = block[scr[0]][i];
}
ptop[scr[0]] -=(ptop[scr[0]]-scr[1]);
}
if(!strcmp("pile", ope1) && !strcmp("over", ope2) )
{
for(int i = scr[1]; i < ptop[scr[0]]; i++)
{
block[dest[0]][ptop[dest[0]]++] = block[scr[0]][i];
}
ptop[scr[0]] -=(ptop[scr[0]]-scr[1]);
}
}
print(nump);
}
void print(int nump)
{
for(int i = 0; i < nump;i++)
{
printf("%d:", i);
for(int j = 0; j < ptop[i]; j++)
printf(" %d", block[i][j]);
putchar('\n');
}
}
void backtoini(int line, int from, int to)
{
for(int i = from; i <= to; i++)
{
int temp = block[line][i];
block[temp][0] = temp;
ptop[temp]++;
ptop[line]--;
}
}
101UVa木块问题
最新推荐文章于 2018-02-11 22:24:36 发布