-
Notifications
You must be signed in to change notification settings - Fork 13
/
detective-pikaptcha-ep2.c
134 lines (122 loc) · 5.09 KB
/
detective-pikaptcha-ep2.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef enum DIR {
right = 0,
bot = 1,
left = 2,
top = 3
} _dir;
typedef enum SIDE {
leftW = 0,
rightW = 1
} _side;
char line[103][103], sd[2];
char directions[] = { '>', 'v', '<', '^' };
char sides[] = { 'L', 'R' };
main()
{
char tmp[256];
int w, h; scanf("%d%d", &w, &h);
int pos_x, pos_y;
int cur_x, cur_y;
_dir dir;
_side side;
for (int i = 0; i < 103; i++)
for (int j = 0; j < 103; j++)
line[i][j] = '#';
for (int i = 1; i <= h; i++) {
scanf("%s", tmp);
for (int t = 0; t < w; t++) { line[i][t+1] = tmp[t]; }
for (int j = 1; j <= w; j++) {
for (int d = 0; d < 4; d++)
if(line[i][j] == directions[d]) { pos_x = i; pos_y = j; dir = d; break; }
}
}
for (int i = 0; i <= h+1; i++) {
for (int j = 0; j <= w+1; j++) { fprintf(stderr, "%c", line[i][j]); }
fprintf(stderr, "\n");
}
scanf("%s", sd);
side = (sd[0] == sides[0]) ? leftW : rightW;
cur_x = pos_x; cur_y = pos_y;
line[cur_x][cur_y] = '0';
if( line[cur_x-1][cur_y ] == '#' &&
line[cur_x+1][cur_y ] == '#' &&
line[cur_x ][cur_y-1] == '#' &&
line[cur_x ][cur_y+1] == '#')
{
for (int i = 1; i <= h; i++) {
for(int j = 1; j <= w; j++) { printf("%c", line[i][j]); }
printf("\n");
}
return;
}
do {
if(side == leftW)
{
switch(dir)
{
case right:
if ( line[cur_x-1][cur_y ] != '#' ) { cur_x--; dir = top; }
else if( line[cur_x ][cur_y+1] != '#' ) { cur_y++; dir = right; }
else if( line[cur_x+1][cur_y ] != '#' ) { cur_x++; dir = bot; }
else { cur_y--; dir = left; }
break;
case bot :
if ( line[cur_x ][cur_y+1] != '#' ) { cur_y++; dir = right; }
else if( line[cur_x+1][cur_y ] != '#' ) { cur_x++; dir = bot; }
else if( line[cur_x ][cur_y-1] != '#' ) { cur_y--; dir = left; }
else { cur_x--; dir = top; }
break;
case left :
if ( line[cur_x+1][cur_y ] != '#' ) { cur_x++; dir = bot; }
else if( line[cur_x ][cur_y-1] != '#' ) { cur_y--; dir = left; }
else if( line[cur_x-1][cur_y ] != '#' ) { cur_x--; dir = top; }
else { cur_y++; dir = right; }
break;
case top :
if ( line[cur_x ][cur_y-1] != '#' ) { cur_y--; dir = left; }
else if( line[cur_x-1][cur_y ] != '#' ) { cur_x--; dir = top; }
else if( line[cur_x ][cur_y+1] != '#' ) { cur_y++; dir = right; }
else { cur_x++; dir = bot; }
default: break;
}
}
else
{
switch(dir)
{
case right:
if ( line[cur_x+1][cur_y ] != '#' ) { cur_x++; dir = bot; }
else if( line[cur_x ][cur_y+1] != '#' ) { cur_y++; dir = right; }
else if( line[cur_x-1][cur_y ] != '#' ) { cur_x--; dir = top; }
else { cur_y--; dir = left; }
break;
case bot :
if ( line[cur_x ][cur_y-1] != '#' ) { cur_y--; dir = left; }
else if( line[cur_x+1][cur_y ] != '#' ) { cur_x++; dir = bot; }
else if( line[cur_x ][cur_y+1] != '#' ) { cur_y++; dir = right; }
else { cur_x--; dir = top; }
break;
case left :
if ( line[cur_x-1][cur_y ] != '#' ) { cur_x--; dir = top; }
else if( line[cur_x ][cur_y-1] != '#' ) { cur_y--; dir = left; }
else if( line[cur_x+1][cur_y ] != '#' ) { cur_x++; dir = bot; }
else { cur_y++; dir = right; }
break;
case top :
if ( line[cur_x ][cur_y+1] != '#' ) { cur_y++; dir = right; }
else if( line[cur_x-1][cur_y ] != '#' ) { cur_x--; dir = top; }
else if( line[cur_x ][cur_y-1] != '#' ) { cur_y--; dir = left; }
else { cur_x++; dir = bot; }
default: break;
}
}
line[cur_x][cur_y]++;
} while(cur_x != pos_x || cur_y != pos_y);
for (int i = 1; i <= h; i++) {
for(int j = 1; j <= w; j++) { printf("%c", line[i][j]); }
printf("\n");
}
}