Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 又是一水？

Posted by KatrineYang at 2016-11-12 14:26:59 on Problem 1573
```#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
while(1){
int x,y,e;
char instr[15][15];
scanf("%d%d%d",&x,&y,&e);
if(!x) break;
for(int i = 1; i <= x; i++){
char tmp[233];
scanf("%s", tmp);
for(int j = 1; j <= y; j++){
instr[i][j] = tmp[j-1];
}
}
int cnt = 0;
int X = 1, Y = e;
int sx[15][15];
for(int i = 1; i <= x; i++){
for(int j = 1; j <= y; j++){
sx[i][j] = -1;
}
}
while(1){
if(X==0 || Y==0 || X==x+1 || Y==y+1){
printf("%d step(s) to exit\n", cnt);
break;
}
if(sx[X][Y] != -1){
printf("%d step(s) before a loop of %d step(s)\n", sx[X][Y], cnt-sx[X][Y]);
break;
}
sx[X][Y] = cnt;
cnt++;
switch(instr[X][Y]){
case 'N': X--; break;
case 'S': X++; break;
case 'W': Y--; break;
case 'E': Y++; break;
}
}
}
return 0;
}
```

Followed by: