//http://w...content-available-to-author-only...m.br/meublog/competir/robo-colecionador-maratona2010/
//https://w...content-available-to-author-only...m.br/judge/problems/view/1121
#include<stdio.h>
struct pos {
int x;
int y;
int prox_x;
int prox_y;
}pos;
int main (void) {
int L, C, S;
while (scanf("%d %d %d", &L
, &C
, &S
)&&L
!=0) { int i, j, fig=0;
char tab[L][C], cmd[S+1];
for(i=0; i<L; i++) {
for(j=0; j<C; j++) {
if(tab[i][j]!='.'&&tab[i][j]!='*'&&tab[i][j]!='#') {
pos.x=i;
pos.y=j;
switch (tab[i][j]) {
case 'N':
pos.prox_x=i-1;
pos.prox_y=j;
break;
case 'S':
pos.prox_x=i+1;
pos.prox_y=j;
break;
case 'L':
pos.prox_x=i;
pos.prox_y=j+1;
break;
case 'O':
pos.prox_x=i;
pos.prox_y=j-1;
break;
}
}
}
}
for (i=0; i<S; i++) {
switch (cmd[i]) {
case 'D':
if (pos.prox_y==pos.y) {
if (pos.prox_x>pos.x) {
pos.prox_x=pos.x;
pos.prox_y=pos.y-1;
}
else {
pos.prox_x=pos.x;
pos.prox_y=pos.y+1;
}
}
else {
if (pos.prox_y>pos.y) {
pos.prox_y=pos.y;
pos.prox_x=pos.x+1;
}
else {
pos.prox_y=pos.y;
pos.prox_x=pos.x-1;
}
}
break;
case 'E':
if (pos.prox_x==pos.x) {
if (pos.prox_y>pos.y) {
pos.prox_y=pos.y;
pos.prox_x=pos.x-1;
}
else {
pos.prox_y=pos.y;
pos.prox_x=pos.x+1;
}
}
else {
if (pos.prox_x>pos.x) {
pos.prox_x=pos.x;
pos.prox_y=pos.y+1;
}
else {
pos.prox_x=pos.x;
pos.prox_y=pos.y-1;
}
}
break;
case 'F':
if (tab[pos.prox_x][pos.prox_y]!='#'&&(pos.prox_x<L&&pos.prox_x>-1)&&(pos.prox_y<C&&pos.prox_y>-1)) {
if (tab[pos.prox_x][pos.prox_y]=='*') {
tab[pos.prox_x][pos.prox_y]='.';
fig++;
}
if (pos.prox_y==pos.y) {
if (pos.prox_x>pos.x) {
pos.x=pos.prox_x;
pos.prox_x++;
}
else {
pos.x=pos.prox_x;
pos.prox_x--;
}
}
else {
if (pos.prox_y>pos.y) {
pos.y=pos.prox_y;
pos.prox_y++;
}
else {
pos.y=pos.prox_y;
pos.prox_y--;
}
}
}
break;
}
}
}
return 0;
}
Ly9odHRwOi8vdy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4ubS5ici9tZXVibG9nL2NvbXBldGlyL3JvYm8tY29sZWNpb25hZG9yLW1hcmF0b25hMjAxMC8KLy9odHRwczovL3cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLm0uYnIvanVkZ2UvcHJvYmxlbXMvdmlldy8xMTIxCgojaW5jbHVkZTxzdGRpby5oPgpzdHJ1Y3QgcG9zIHsKICAgIGludCB4OwogICAgaW50IHk7CiAgICBpbnQgcHJveF94OwogICAgaW50IHByb3hfeTsKfXBvczsKCmludCBtYWluICh2b2lkKSB7CiAgICBpbnQgTCwgQywgUzsKICAgIHdoaWxlIChzY2FuZigiJWQgJWQgJWQiLCAmTCwgJkMsICZTKSYmTCE9MCkgewogICAgICAgIGludCBpLCBqLCBmaWc9MDsKICAgICAgICBjaGFyIHRhYltMXVtDXSwgY21kW1MrMV07CiAgICAgICAgZ2V0Y2hhcigpOwogICAgICAgIGZvcihpPTA7IGk8TDsgaSsrKSB7CiAgICAgICAgICAgIGZvcihqPTA7IGo8QzsgaisrKSB7CiAgICAgICAgICAgICAgICB0YWJbaV1bal09Z2V0Y2hhcigpOwogICAgICAgICAgICAgICAgaWYodGFiW2ldW2pdIT0nLicmJnRhYltpXVtqXSE9JyonJiZ0YWJbaV1bal0hPScjJykgewogICAgICAgICAgICAgICAgICAgIHBvcy54PWk7CiAgICAgICAgICAgICAgICAgICAgcG9zLnk9ajsKICAgICAgICAgICAgICAgICAgICBzd2l0Y2ggKHRhYltpXVtqXSkgewogICAgICAgICAgICAgICAgICAgICAgICBjYXNlICdOJzoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3g9aS0xOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeT1qOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIGNhc2UgJ1MnOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeD1pKzE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF95PWo7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgY2FzZSAnTCc6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF94PWk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF95PWorMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICBjYXNlICdPJzoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3g9aTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3k9ai0xOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGdldGNoYXIoKTsKICAgICAgICB9CiAgICAgICAgc2NhbmYoIiVzIiwgY21kKTsKICAgICAgICBmb3IgKGk9MDsgaTxTOyBpKyspIHsKICAgICAgICAgICAgc3dpdGNoIChjbWRbaV0pIHsKICAgICAgICAgICAgICAgIGNhc2UgJ0QnOgogICAgICAgICAgICAgICAgICAgIGlmIChwb3MucHJveF95PT1wb3MueSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAocG9zLnByb3hfeD5wb3MueCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeD1wb3MueDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3k9cG9zLnktMTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3g9cG9zLng7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF95PXBvcy55KzE7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwb3MucHJveF95PnBvcy55KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF95PXBvcy55OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeD1wb3MueCsxOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeT1wb3MueTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3g9cG9zLngtMTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgJ0UnOgogICAgICAgICAgICAgICAgICAgIGlmIChwb3MucHJveF94PT1wb3MueCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAocG9zLnByb3hfeT5wb3MueSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeT1wb3MueTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3g9cG9zLngtMTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3k9cG9zLnk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF94PXBvcy54KzE7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwb3MucHJveF94PnBvcy54KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF94PXBvcy54OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeT1wb3MueSsxOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnByb3hfeD1wb3MueDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3k9cG9zLnktMTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgJ0YnOgogICAgICAgICAgICAgICAgICAgIGlmICh0YWJbcG9zLnByb3hfeF1bcG9zLnByb3hfeV0hPScjJyYmKHBvcy5wcm94X3g8TCYmcG9zLnByb3hfeD4tMSkmJihwb3MucHJveF95PEMmJnBvcy5wcm94X3k+LTEpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0YWJbcG9zLnByb3hfeF1bcG9zLnByb3hfeV09PScqJykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGFiW3Bvcy5wcm94X3hdW3Bvcy5wcm94X3ldPScuJzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpZysrOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwb3MucHJveF95PT1wb3MueSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBvcy5wcm94X3g+cG9zLngpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MueD1wb3MucHJveF94OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3grKzsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MueD1wb3MucHJveF94OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvcy5wcm94X3gtLTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwb3MucHJveF95PnBvcy55KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnk9cG9zLnByb3hfeTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF95Kys7CgogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zLnk9cG9zLnByb3hfeTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MucHJveF95LS07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIHByaW50ZigiJWRcbiIsIGZpZyk7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==
MyAzIDIKKioqCipOKgoqKioKREUKNCA0IDUKLi4uIwoqI08uCiouKi4KKi4jLgpGRkVGRgoxMCAxMCAyMAouLi4uKi4uLi4uCi4uLi4uLi4qLi4KLi4uLi4qLi4uLgouLiouIy4uLi4uCi4uLiNOLiouLioKLi4uKi4uLi4uLgouLi4uLi4uLi4uCi4uLi4uLi4uLi4KLi4uLi4uLi4uLgouLi4uLi4uLi4uCkZERkZGRkZGRUVGRkZGRkZFRkRGCjAgMCAw
3 3 2
***
*N*
***
DE
4 4 5
...#
*#O.
*.*.
*.#.
FFEFF
10 10 20
....*.....
.......*..
.....*....
..*.#.....
...#N.*..*
...*......
..........
..........
..........
..........
FDFFFFFFEEFFFFFFEFDF
0 0 0