-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path101.c
111 lines (109 loc) · 1.81 KB
/
101.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include<stdio.h>
#include<string.h>
int a[30][30];
void search(int key,int n,int *x,int *y)
{
int i,j;
for (i=0;i<n;i++)
{
j=0;
while (a[i][j++]!=-1)
if (a[i][j-1]==key)
{
*x=i;
*y=j-1;
return ;
}
}
}
void monto(int xa,int ya,int xb,int yb)
{
int i=yb+1,j=ya+1,k;
while (a[xa][j++]!=-1)
{
a[a[xa][j-1]][0]=a[xa][j-1];
a[a[xa][j-1]][1]=-1;
}
while (a[xb][i++]!=-1)
{
a[a[xb][i-1]][0]=a[xb][i-1];
a[a[xb][i-1]][1]=-1;
}
a[xb][yb+1]=a[xa][ya];
a[xb][yb+2]=-1;
a[xa][ya]=-1;
}
void mover(int xa,int ya,int xb,int yb)
{
int j=ya+1,i=yb;
while (a[xa][j++]!=-1)
{
a[a[xa][j-1]][0]=a[xa][j-1];
a[a[xa][j-1]][1]=-1;
}
while (a[xb][i++]!=-1);
a[xb][i-1]=a[xa][ya];
a[xb][i]=-1;
a[xa][ya]=-1;
}
void ponto(int xa,int ya,int xb,int yb)
{
int i=yb+1,j=ya;
while (a[xb][i++]!=-1)
{
a[a[xb][i-1]][0]=a[xb][i-1];
a[a[xb][i-1]][1]=-1;
}
while (a[xa][j++]!=-1)
a[xb][++yb]=a[xa][j-1];
a[xb][yb+1]=-1;
a[xa][ya]=-1;
}
void pover(int xa,int ya,int xb,int yb)
{
int i=ya,j=yb;
while (a[xb][j++]!=-1);
while (a[xa][i++]!=-1)
a[xb][j++-1]=a[xa][i-1];
a[xa][ya]=-1;
a[xb][j-1]=-1;
}
main()
{
int i,j,k,l,m,n;
scanf("%d",&n);
getchar();
memset(a,-1,sizeof(a));
for (i=0;i<n;i++)
a[i][0]=i;
char s1[10],s2[10];
int _a,b,xa,ya,xb,yb;
while (scanf("%s%d%s%d",s1,&_a,s2,&b)>0)
{
search(_a,n,&xa,&ya);
search(b,n,&xb,&yb);
if (xa==xb) continue;
if (s1[0]=='m' && s2[3]=='o')
monto(xa,ya,xb,yb);
else
if (s1[0]=='m' && s2[3]=='r')
mover(xa,ya,xb,yb);
else
if (s1[0]=='p' && s2[3]=='o')
ponto(xa,ya,xb,yb);
else
if (s1[0]=='p' && s2[3]=='r')
pover(xa,ya,xb,yb);
else
if (s1[0]=='q') break;
}
for (i=0;i<n;i++)
{
printf("%d:",i);
j=0;
while (a[i][j++]!=-1)
printf(" %d",a[i][j-1]);
putchar('\n');
}
return 0;
}