//#include #include #include #include using namespace std; void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. typedef struct{ int row; int col; string str; //bool visited; }Vertex; //Vertex vertex[200][200]; int count = 0; //int flag = 0; //int flagFor = 0; //int flagWhile = 0; int numVertex = n*n; bool visited[200][200] = { false }; /*string str1, str2, str3, str4, str5, str6; int flagStr1 =0, flagStr2 = 0, flagStr3 = 0, flagStr4 = 0, flagStr5 = 0, flagStr6 = 0; */ queue Q; Vertex start = { i_start, j_start }; visited[i_start][j_start] = true; Q.push(start); /*while(numVertex-1) {*/ while(!Q.empty()){ Vertex v = Q.front(); Q.pop(); for(int i = 1; i <= 6; i++){ switch(i){ case 1://UL if(v.row - 2 >= 0 && v.col - 1 >= 0 && visited[v.row - 2][v.col - 1] == false) { visited[v.row - 2][v.col - 1] =true; Vertex temp = { v.row - 2, v.col - 1 ,v.str+"UL "}; //vertex[v.row - 2][v.col - 1].str += "UL "; Q.push(temp); //str1 += "UL "; if(temp.row == i_end && temp.col == j_end) { //flag = 1; //flagStr1 = 1; for(int i =0;i= 0 && v.col + 1 = 0 && visited[v.row + 2][v.col - 1] == false) { visited[v.row + 2][v.col - 1] = true; Vertex temp = { v.row + 2, v.col - 1 , v.str+"LL "}; Q.push(temp); //str5 += "LL "; if(temp.row == i_end && temp.col == j_end) { //flag = 1; //flagStr5 = 1; for(int i =0;i= 0 && visited[v.row][v.col - 2] == false) { visited[v.row][v.col - 2] = true; Vertex temp = { v.row, v.col - 2 ,v.str+"L "}; //vertex[v.row ][v.col - 2].str += "L "; Q.push(temp); //str6 += "L "; if(temp.row == i_end && temp.col == j_end) { //flag = 1; //flagStr6 = 1; for(int i =0;i> n; int i_start; int j_start; int i_end; int j_end; cin >> i_start >> j_start >> i_end >> j_end; printShortestPath(n, i_start, j_start, i_end, j_end); return 0; }