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
135
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int h, w;
int sy, sx, dir;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
char dd[4] = {'E', 'S', 'W', 'N'};
bool can(int y, int x) {
if(0 <= y && y < h && 0 <= x && x < w) return true;
return false;
}
int main() {
ll l;
while(cin >> h >> w >> l) {
if(h == 0 && w == 0 && l == 0) break;
vector<string> v(h);
rep(i, h) cin >> v[i];
rep(i, h) {
rep(j, w) {
if(v[i][j] == 'E') {
sy = i; sx = j;
dir = 0;
v[i][j] = '.';
}
else if(v[i][j] == 'S') {
sy = i; sx = j;
dir = 1;
v[i][j] = '.';
}
else if(v[i][j] == 'W') {
sy = i; sx = j;
dir = 2;
v[i][j] = '.';
}
else if(v[i][j] == 'N') {
sy = i; sx = j;
dir = 3;
v[i][j] = '.';
}
}
}
ll d[105][105][4];
memset(d, -1, sizeof(d));
vector<int> X, Y, D;
int y = sy, x = sx, cnt = 0;
rep(i, 4) {
int ny = y + dy[(dir + i) % 4];
int nx = x + dx[(dir + i) % 4];
if(can(ny, nx) && v[ny][nx] == '.') {
dir = (dir + i) % 4;
break;
}
}
int pdir = dir;
d[y][x][dir] = cnt;
cnt++;
while(l) {
y = y + dy[dir];
x = x + dx[dir];
pdir = dir;
l--;
rep(i, 4) {
int ny = y + dy[(dir + i) % 4];
int nx = x + dx[(dir + i) % 4];
if(can(ny, nx) && v[ny][nx] == '.') {
dir = (dir + i) % 4;
break;
}
}
if(d[y][x][dir] == -1) {
d[y][x][dir] = cnt;
cnt++;
} else {
break;
}
}
if(l == 0) {
cout << y + 1 << " " << x + 1 << " " << dd[pdir] << endl;
continue;
}
ll len = cnt - d[y][x][dir];
l = l % len;
dir = pdir;
rep(i, l) {
rep(j, 4) {
int ny = y + dy[(dir + j) % 4];
int nx = x + dx[(dir + j) % 4];
if(can(ny, nx) && v[ny][nx] == '.') {
y = ny; x = nx;
dir = (dir + j) % 4;
break;
}
}
}
cout << y + 1 << " " << x + 1 << " " << dd[dir] << endl;
}
return 0;
}
|