Solution C ++ job 01

xiaoxiao2021-03-06  84

#include #include #include #include #include using namespace std;

INT Find (Char CH, INT & X, INT & W, String OpenMAZE, INT & WIDTH) {String Str; IFSTREAM FIN (OpenMAZE.C_STR ()); if (! fin) {cout << "can't open << ENDL Return 0;} while (getLine (FIN, STR)) {x ; y = str.find (CH, 0); if (y! = String :: npos) Break;} width = str.size (); FIN .Close (); x--; return 1;} // Find 'e' and return width

INT LoadMap (String * Load, String OpenMAZE, INT & HEIGHT) {String Str; ifstream FIN (OpenMAZE.C_STR ()); if (! fin) {cout << "can't open << endl; return 0; } While (getLine (FIN, STR)) {load [height] = Str; Height ;} fin.close (); return 1;} // load the map info a string pointer and return height //Method: // 1 .R 2.d 3.l 4.u // o ------> // | | // | <--- VBool Findway (int X, int y, string * load) {loading [ X] [y] = 'o'; if (LOAD [x 1] [Y] == 'x') Return True; if (LOAD [X-1] [Y] == 'x') Return True; IF (LOAD [X] == 'x') Return True; if (LOAD [X] [Y-1] == 'x') Return True; IF (Load [x] [y 1 ] == '.') {IF (Findway (X, Y 1, LOAD) == True) Return true;} if (LOAD [x 1] [Y] == '.') {IF (Findway X 1, Y, LOAD == True) Return True;} if (Load [x] [Y-1] == '.') {IF (Findway (X, Y-1, Load) == TRUE) Return true;} = == '.') {IF (Findway (X-1, Y, Load) == true) Return true;} loading [x] [y] = '.'; Return False;} // use square to sign where it is been, if can set, turn it back to '.'

INT main () {INT I, Width = 0, Height = 0; INT x = 0, y = 0, x1 = 0, Y1 = 0; // int Director; string openmaze; cout << "Which map do you like TO Play? maze1.txt or maze2.txt? "<< Endl; cin >> openmaze; cout << Endl; if (Find ('e', x, y, openmaze, width) {cout <<" can Find "; cout <<" x: << x << "Y:" << Y << "!" << Endl;} else {cout << "" can't find entrance! "<< Endl; Return 1;} IF (Find ('x1, y1, openmaze, width) {cout << "can find exit"; cout << "x: << x1 <<" Y: << Y1 < <"!" << Endl;} else {cout << "can't Find Exit! << endl; return 1;} string * load = new string [width]; // create the string pointer to load maploadMAP Load, openmaze, height; cout << "The map is:" Height << "*" << width << "TYPE." << endl; loading [x] [y] = '/ 004'; LOAD [x1] = '/ 004'; for (i = 0; i <= height; i ) cout << LOAD [i] << end1

LOAD [x1] = 'x'; IF (Findway (X, Y, Load)) {cout << "can Find the Way! << Endl; for (i = 0; i <= height; i ) Cout << LOAD [i] << Endl;} else cout << "can't find, sorry!" << end1; delete [] load; return 0;}

转载请注明原文地址:https://www.9cbs.com/read-100979.html

New Post(0)