-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUMMER_Lab01_1.c
62 lines (58 loc) · 1.51 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
#include <stdio.h>
int main()
{
char king[3];
char rock[3];
int n;
char move[3];
int move_num[2];
int i, j;
scanf("%s", king);
scanf("%s", rock);
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%s", move);
move_num[0] = 0;
move_num[1] = 0;
for (j = 0; j < 3; j++)
{
switch (move[j])
{
case 'R':
move_num[0]++;
break;
case 'L':
move_num[0]--;
break;
case 'T':
move_num[1]++;
break;
case 'B':
move_num[1]--;
break;
}
}
king[0] = king[0] + move_num[0];
king[1] = king[1] + move_num[1];
if (!('A' <= king[0] && king[0] <= 'H') || !('1' <= king[1] && king[1] <= '8'))
{
king[0] = king[0] - move_num[0];
king[1] = king[1] - move_num[1];
}
if (king[0] == rock[0] && king[1] == rock[1])
{
rock[0] = rock[0] + move_num[0];
rock[1] = rock[1] + move_num[1];
if (!('A' <= rock[0] && rock[0] <= 'H') || !('1' <= rock[1] && rock[1] <= '8'))
{
king[0] = king[0] - move_num[0];
king[1] = king[1] - move_num[1];
rock[0] = rock[0] - move_num[0];
rock[1] = rock[1] - move_num[1];
}
}
}
printf("%s\n%s", king, rock);
return 0;
}