📄 13vii.cpp
字号:
// Maze.cpp Implementation file for the Maze class
#include <iostream.h>
#include "Maze.h"
void Maze::Solve (int x, int y)
{ Recursive_Solve (x, y);
cout << " maze is solved" << endl;
}
int Maze::Recursive_Solve (int x, int y)
{ int success = 0;
switch (cells[x][y])
{ case 'g' : success = 1; break;
case '*' : success = 0; break;
case 'f' : success = 0; break;
default : cells[x][y] = 'f'; // leave a footprint..
success = Recursive_Solve(x+1, y) +
Recursive_Solve(x-1, y) +
Recursive_Solve(x, y+1) +
Recursive_Solve(x, y-1); break;
}
if (success > 0) cout << x << "," << y << endl;
return (success);
}
void Maze::Input (istream& in)
{ int row, col;
for (row=0; row<10; row++)
for (col=0; col<10; col++)
in >> cells[col][row];
}
// wrapper function for the extraction operator
istream& operator >> (istream& in, Maze& m)
{ m.Input (in);
return (in);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -