Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int I = 1, J = 1, S = 1;
- while (I != 0 && J != 0 && S != 0)
- {
- scanf("%d %d %d", &I, &J, &S);
- //cout << I << " " << J << " " << S << endl;
- int pathN[10010][10010]; //Path nunber (row and collum)
- char pathI[10010][10010]; //Path instruction (N || S || W || E)
- int pathS[10010][10010]; //Path steps until now
- for (int i = 0; i < I; i++)
- {
- char linha[10010];
- scanf("%c", linha);
- for (int j = 0; j < J; j++)
- {
- pathN[i][j] = 0;
- pathI[i][j] = linha[j];
- pathS[i][j] = 0;
- }
- }
- int end = 0;
- int iNow = 0;
- int jNow = S - 1;
- int stepsNow = 0;
- while (end == 0)
- {
- pathN[iNow][jNow]++;
- //Loop
- if (pathN[iNow][jNow] > 1)
- {
- int stepsBL = pathS[iNow][jNow]; //Before the loop
- int stepsL = stepsNow - stepsBL; //In the loop
- printf("%d step(s) before a loop of %d step(s)", stepsBL, stepsL);
- end++;
- }
- if (pathN[iNow][jNow] == 1)
- {
- stepsNow++;
- pathS[iNow][jNow] = stepsNow;
- if (pathI[iNow][jNow] == 'N')
- {
- iNow--;
- }
- else if (pathI[iNow][jNow] == 'S')
- {
- iNow++;
- }
- else if (pathI[iNow][jNow] == 'W')
- {
- jNow--;
- }
- else if (pathI[iNow][jNow] == 'E')
- {
- jNow++;
- }
- }
- //Saiu da parada
- if (iNow < 0 || iNow > I - 1 || jNow < 0 || jNow > J - 1)
- {
- printf("%d step(s) to exit", stepsNow);
- end++;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement