Maze Traversal

Hello I'm having a little problem here
please visit this site to read full description of the problem
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1318


the code is not working properly....
and here is the code :

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
# include <iostream>
# include <string>
# include <stdio.h>
using namespace std ;
int main ()
{
	int T , row1 , col1 , IniROW , IniCOL , Prow , Pcol ;
	char matrix [70][70]  ;
	char directions [1000000] ;
	cin >> T ;
	cout << endl;
	for (int i=0 ; i<T ; i++)
	{
		cin >> row1 >> col1 ;
		cin.ignore ();
		for (int row=0 ; row<row1 ;row++)
		{
			for (int col=0 ; col<col1 ; col++)
			{
				matrix [row][col] = getchar () ;
			}
			cin.ignore () ;
		}
		cin >> IniROW >> IniCOL ;
		int counter = 0 ;
		cin.ignore () ;
		for (int j=0 ; j<100000 ; j++)
		{
			cin >> directions [j] ;
			counter ++ ;
			if (directions [j] == 'Q')
			{
				break ;
			}
			if ( (directions [j] =='\n' && directions [j] !='Q') || (directions [j] ==' ' && directions [j] !='Q') )
			{
				continue ;
			}
		}
		string head = "north";
		Prow = IniROW-1 ;
		Pcol = IniCOL-1 ;
		for (int j=0 ;j<counter-1 ;j++)
		{
			if (directions [j] == 'R' && head == "north" )
			{
				head = "east" ;
			}
			else if (directions [j] == 'R' && head == "east")
			{
				head = "south" ;
			}
			else if (directions [j] == 'R' && head == "south" )
			{
				head = "west" ;
			}
			else if (directions [j] == 'R' && head == "west" )
			{
				head = "north" ;
			}
			if (directions [j] == 'L' && head == "north" )
			{
				head = "west" ;
			}
			else if (directions [j] == 'L' && head == "west")
			{
				head = "south" ;
			}
			else if (directions [j] == 'L' && head == "south" )
			{
				head = "east" ;
			}
			else if (directions [j] == 'L' && head == "east" )
			{ 
				head = "north";
			}
			if (directions [j] == 'F' && head =="east" && matrix[Prow][Pcol+1] == ' ' )
			{
				Prow = Prow ;
				Pcol = Pcol+1 ;
			}
			else if (directions [j] == 'F' && head =="south" && matrix[Prow+1][Pcol] == ' ')
			{
				Prow = Prow +1 ;
				Pcol = Pcol ;
			}
			else if (directions [j] == 'F' && head =="west" && matrix[Prow][Pcol-1] == ' ')
			{
				Prow = Prow ;
				Pcol = Pcol-1 ;
			}
			else if (directions [j] == 'F' && head =="north" && matrix[Prow-1][Pcol] == ' ')
			{
				Prow = Prow-1 ;
				Pcol = Pcol ;
			}
		}
		if (head == "north")
		{
			head = "N" ;
		}
		else if (head == "east")
		{
			head = "E" ;
		}
		else if (head == "south")
		{
			head = "S" ;
		}
		else if (head == "west")
		{
			head = "W" ;
		}
		if (i<T-1)
		{
			cout << Prow+1 << " " << Pcol+1 << " " << head << endl;
			cout << endl;
		}
		else 
			cout << Prow+1 << " " << Pcol+1 << " " << head << endl;
	}
	return 0 ;
}
Last edited on
Topic archived. No new replies allowed.