#include #include #include using namespace std; struct position { int row; int col; int level; char left; char right; char front; char back; char upp; char down; }; void Status (position &, char [7][7][11]); int main () { position now; char maze [7][7][11]; stack path; stack hold; int r, c, lev; ifstream block; block.open("maze.txt"); for (lev = 0; lev < 11; lev++) { for (r = 0; r < 7; r++) { for (c = 0; c < 7; c++) { block >> maze[r][c][lev]; } block.ignore(20,'\n'); } } block >> now.row >> now.col >> now.level; Status (now, maze); path.push(now); while (path.top().level != 10) { if (path.top().upp == 'o') { path.top().upp = 'b'; now = path.top(); maze[now.row][now.col][now.level] = 'b'; now.level++; Status (now, maze); path.push(now); } else if (path.top().left == 'o') { path.top().left = 'b'; now = path.top(); maze[now.row][now.col][now.level] = 'b'; now.col--; Status (now, maze); path.push(now); } else if (path.top().front == 'o') { path.top().front = 'b'; now = path.top(); maze[now.row][now.col][now.level] = 'b'; now.row--; Status (now, maze); path.push(now); } else if (path.top().back == 'o') { path.top().back = 'b'; now = path.top(); maze[now.row][now.col][now.level] = 'b'; now.row++; Status (now, maze); path.push(now); } else if (path.top().right == 'o') { path.top().right = 'b'; now = path.top(); maze[now.row][now.col][now.level] = 'b'; now.col++; Status (now, maze); path.push(now); } else if (path.top().down == 'o') { path.top().down = 'b'; now = path.top(); maze[now.row][now.col][now.level] = 'b'; now.level--; Status (now, maze); path.push(now); } else path.pop(); } while (!path.empty()) { hold.push(path.top()); path.pop(); } while (!hold.empty()) { now = hold.top(); cout << now.row << ',' << now.col << ',' << now.level << " "; hold.pop(); } cout << endl; return 0; } void Status (position &now, char maze[7][7][11]) { int r = now.row; int c = now.col; int v = now.level; now.front = maze[r-1][c][v]; now.back = maze[r+1][c][v]; now.left = maze[r][c-1][v]; now.right = maze[r][c+1][v]; now.down = (v >= 0) ? maze[r][c][v-1] : 'b'; now.upp = maze[r][c][v+1]; }