-
Notifications
You must be signed in to change notification settings - Fork 0
/
1147.c
58 lines (42 loc) · 836 Bytes
/
1147.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
//1147
#include <stdio.h>
int main()
{
int tst = 0;
while(1)
{
char c[3];
scanf("%s",c);
getchar();
if(c[0] == '0')
break;
char board[8][8] = {{},{}};
int cx = c[0] - '1';
int cy = c[1] - 'a';
board[cx][cy] = 'C';
int i;
for(i = 0; i < 8; i++)
{
char xy[3];
scanf("%s",xy);
getchar();
int x = xy[0] - '1';
int y = xy[1] - 'a';
board[x][y] = 'P';
}
int mx[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int my[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int moves = 0;
for(i = 0; i < 8; i++)
{
int px = cx + mx[i];
int py = cy + my[i];
if(px >= 0 && px < 8 && py >=0 && py < 8 &&
(board[px+1][py-1] != 'P' &&
board[px+1][py+1] != 'P'))
moves++;
}
printf("Caso de Teste #%d: %d movimento(s).\n",++tst, moves);
}
return 0;
}