-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUMMER_Lab01_1.c
98 lines (81 loc) · 1.93 KB
/
SUMMER_Lab01_1.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
#include <stdio.h>
#define King 1
#define Stone 2
int map[55][55], num, direction_num;
int dx[] = { 1,-1,0,0,1,-1,1,-1 };//R, L, B, T, RT, LT, RB, LB
int dy[] = { 0,0,1,-1,-1,-1,1,1 };
char direction[55][3], king_position[5], stone_position[5], K_x, K_y, S_x, S_y;
void input_position();
int d(char *);
int main()
{
input_position();
while (direction_num < num)
{
int De = d(direction[direction_num++]);
int xx = K_x + dx[De];
int yy = K_y + dy[De];
if (xx < 0 || yy < 0 || xx>7 || yy>7)
continue;
if (map[yy][xx] == Stone)
{
int S_xx = S_x + dx[De];
int S_yy = S_y + dy[De];
if (S_xx < 0 || S_yy < 0 || S_xx>7 || S_yy>7)
continue;
map[S_yy][S_xx] = Stone;
map[S_y][S_x] = 0;
S_x = S_xx;
S_y = S_yy;
}
map[yy][xx] = King;
map[K_y][K_x] = 0;
K_x = xx; K_y = yy;
}
K_y *= -1;
S_y *= -1;
printf("%c%c\n", K_x + 'A', K_y + '8');
printf("%c%c", S_x + 'A', S_y + '8');
return 0;
}
void input_position()
{
scanf("%s %s %d", king_position, stone_position, &num);
K_x = king_position[0] - 'A';
K_y = king_position[1] - '8'; K_y *= -1;
S_x = stone_position[0] - 'A';
S_y = stone_position[1] - '8'; S_y *= -1;
for (int i = 0; i < num; i++)
scanf("%s", direction[i]);
map[K_y][K_x] = King;
map[S_y][S_x] = Stone;
}
int d(char * arr)
{
if (arr[0] == 'R')
{
if (arr[1] == 'T')
return 4;
else if (arr[1] == 'B')
return 6;
else
return 0;
}
if (arr[0] == 'L')
{
if (arr[1] == 'T')
return 5;
else if (arr[1] == 'B')
return 7;
else
return 1;
}
if (arr[0] == 'B')
{
return 2;
}
if (arr[0] == 'T')
{
return 3;
}
}