Graph problem

Hi! So I'm trying to write a program that creates a graph from a given maze. The maze is decently complex and the qualms that it entails are that: you can only move in threes and you can only move in a straight line given the cardinal direction.

For my first step, I'm just trying to read the input file that has the number of nodes in the first line and then for every line after, there are two points and a cardinal direction (N, S, E, W, SW, SE, etc.)

Right now this is the code I have and I'm trying to read each value into three separate arrays or vectors. However, the code is not reading the second line (so the first line of values) and it's repeating the last line instead. It also is not reading the correct cardinal direction..

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
void Maze() {
	int n;
	int s, t;
	string c;
	int x[n+2], y[n+2];
	vector<string> dir;
	int line_count = 0;
	
	//loads file
	string filename, line;
	cout << "Please enter the name of the maze input file:  ";
	cin >> filename;
	ifstream file(filename);
	if(file.is_open()){
		while(getline(file, line)){
			
			if(line_count == 0){
				n = atoi(line.c_str());
			} else {
				for (int i = 0; i < n+2; i++){
					file>>s>>t>>c;
					x[i] = s;
					y[i] = t;
					//cout << c << endl;
					dir.push_back(c);
					
				}
				
				for (int i = 0; i < n + 2; i++){
					cout << x[i] << "    ";
					cout << y[i] << "    ";
					cout << dir.at(i) << endl;
				}
			}
			line_count++;
		} 
		file.close();
	} else {
			cout << "Unable to open file.\n" << endl;
	}	

}


So for more context, this is the real file

91
0 1 E
1 2 E
2 3 E
3 4 E
4 5 E
5 6 E
6 7 E
7 8 E
8 9 E
9 10 E
10 11 E
1 12 S
12 19 S
3 14 SW
14 13 SW
13 19 SW
3 15 S
15 20 S
10 16 S
16 17 S
17 27 S
11 18 S
18 28 S
20 21 E
21 22 E
22 23 E
23 24 E
24 25 E
25 26 E
26 27 E
27 28 E
19 29 S
29 33 S
29 34 SE
20 30 S
30 35 S
27 31 S
31 42 S
31 41 SW
28 32 S
32 43 S
28 31 SW
33 34 E
34 35 E
35 36 E
36 37 E
37 38 E
38 39 E
39 40 E
40 41 E
41 42 E
42 43 E
33 44 S
44 50 S
35 45 S
45 51 S
34 45 SE
45 52 SE
41 46 SW
46 47 SW
47 54 SW
42 48 S
48 57 S
43 49 S
49 58 S
49 57 SW
52 53 E
53 54 E
54 55 E
55 56 E
56 57 E
50 59 S
59 63 S
51 60 S
60 64 S
52 61 SE
61 65 SE
57 62 SW
62 66 SW
57 68 S
58 69 S
66 67 E
67 68 E
68 69 E
63 74 S
64 76 S
63 70 SE
70 76 SE
65 71 SE
66 71 SW
71 79 SW
71 80 SE
68 72 S
72 81 S
69 73 S
74 75 E
75 76 E
76 77 E
77 78 E
78 79 E
79 80 E
74 82 S
76 84 S
76 85 SE
79 86 SW
80 89 SE
81 90 S
73 91 S
82 83 E
83 84 E
84 85 E
85 86 E
86 87 E
87 88 E
88 89 E
89 90 E
90 91 E
84 92 S


and this is my output:


1    2    E
2    3    E
3    4    E
4    5    E
5    6    E
6    7    E
7    8    E
8    9    E
9    10    E
10    11    E
1    12    E
12    19    E
3    14    E
14    13    E
13    19    E
3    15    E
15    20    E
10    16    E
16    17    E
17    27    E
11    18    E
18    28    E
20    21    E
21    22    E
22    23    E
23    24    E
24    25    E
25    26    E
26    27    E
27    28    E
19    29    E
29    33    E
29    34    E
20    30    E
30    35    E
27    31    E
31    42    E
31    41    E
28    32    E
32    43    E
28    31    E
33    34    E
34    35    E
35    36    E
36    37    E
37    38    E
38    39    E
39    40    E
40    41    E
41    42    E
42    43    E
33    44    E
44    50    E
35    45    E
45    51    E
34    45    E
45    52    E
41    46    E
46    47    E
47    54    E
42    48    E
48    57    E
43    49    E
49    58    E
49    57    E
52    53    E
53    54    E
54    55    E
55    56    E
56    57    E
50    59    E
59    63    E
51    60    E
60    64    E
52    61    E
61    65    E
57    62    E
62    66    E
57    68    E
58    69    E
66    67    E
67    68    E
68    69    E
63    74    E
64    76    E
63    70    E
70    76    E
65    71    E
66    71    E
71    79    E
71    80    E
68    72    E
72    81    E
69    73    E
74    75    E
75    76    E
76    77    E
77    78    E
78    79    E
79    80    E
74    82    E
76    84    E
76    85    E
79    86    E
80    89    E
81    90    E
73    91    E
82    83    E
83    84    E
84    85    E
85    86    E
86    87    E
87    88    E
88    89    E
89    90    E
90    91    E
84    92    E
84    92    E


Can anyone help with this?
Last edited on
I presume you must start at zero and stop at ninety-two? I've drawn the graph by hand and I can't solve it by stepping by three in only one direction at a time.

So I surely misunderstand something. Can you clarify exactly how you are supposed to traverse the graph?
Topic archived. No new replies allowed.