dfs寻找循环节
/*author: birdstorm*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#define MAXN 105
#define N 105
#define INF 1<<30
#define eps 1.0e-10
#define For(i,m,n) for(i=(m);i<n;i++)
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
char str[MAXN][MAXN];
long long vis[MAXN][MAXN][4];
int move[4][2]={0,-1,1,0,0,1,-1,0};
int H, W, cnt;
long long L;
main()
{
int i, j;
int x, y, z, tx, ty;
char *p="NESW";
while(scanf("%d%d%lld",&H,&W,&L),H||W||L){
memset(vis,0,sizeof(vis));
memset(str,0,sizeof(str));
For(i,1,H+1){
scanf("%s",str[i]+1);
For(j,1,W+1){
if(str[i][j]!='.'&&str[i][j]!='#'){
x=j; y=i;
if(str[i][j]=='N') z=0;
if(str[i][j]=='E') z=1;
if(str[i][j]=='S') z=2;
if(str[i][j]=='W') z=3;
str[i][j]='.';
}
}
}
//For(i,1,H+1) {For(j,1,W+1) printf("%c",str[i][j]); puts("");}
for(cnt=0;L;L--,cnt++){
if(vis[y][x][z]){
L=L%(cnt-vis[y][x][z]);
if(!L) break;
}
vis[y][x][z]=cnt;
while(1){
tx=x+move[z][0];
ty=y+move[z][1];
if(str[ty][tx]=='.') break;
z=(z+1)%4;
}
x=tx, y=ty;
}
printf("%d %d %c\n",y,x,*(p+z));
}
return 0;
}