#include using namespace std; int main (int argc, char * const argv[]) { int n, m, i, j, startx, starty, small[30], currentx, currenty, direction, flag1= 0, flag2= 0; int finishx[30], finishy[30]; cout << "\n\nNew Horizons Governors School Team B\n"; cout << "Enter the number of rows: "; cin >> m; cout << "Enter the number of columns: "; cin >> n; char board[m][n]; cout << endl; cout << "Put spaces between characters, use capital letters, enter at the end of a row\n"; cout << "Enter board: " << endl; for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) { cin >> board[i][j]; if (board[i][j] == 'A') { board[i][j] = 'G'; startx = i; starty = j; } } cout << endl; } int fcount = 0, smalla = 1000, smallb = 1000; int finishDistance[20]; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (board[i][j] == 'S') { finishDistance[fcount] = 0; finishx[fcount] = i; finishy[fcount] = j; if (i > startx) finishDistance[fcount] = i - startx; else finishDistance[fcount] = startx - i; if (j > starty) finishDistance[fcount] += j - starty; else finishDistance[fcount] += starty - j; small[fcount] = finishDistance[fcount]; if (finishDistance[fcount] < smalla) { smallb = smalla; smalla = finishDistance[fcount]; } } } } fcount--; int ndirectx, ndirecty; cout << endl << endl << "Answer: " << smalla << endl; do { currentx = startx; currenty = starty; if (currentx != finishx[fcount]) { if (currentx < finishx[fcount]) ndirectx = 1; else ndirectx = 2; } if (currenty != finishy[fcount]) { if (currenty < finishy[fcount]) ndirecty = 3; else ndirecty = 4; } else ndirecty = 0; } while(ndirecty != 0 && ndirectx != 0); return 0; }