// 2023 IUSB Programming Competition // Round 2 Problem 2 // Word Search // Solution by Liguo Yu #include #include using namespace std; bool check(char ** array, int x, int y, int m, int n, string word); int main() { string word; int x, y; cin >> word; cin >> x; cin >> y; char ** array = new char *[x]; for (int i=0; i> word; array[i][j] = word.at(0); } } bool found = false; for (int i=0; i=0; j--) { s = s + array[m][j]; } if(s.find(word)!= string::npos) return true; //vertically downward s = ""; for (int i=m; i=0; i--) { s = s + array[i][n]; } if(s.find(word)!= string::npos) return true; // diagonally: /up s = ""; int i = m; int j = n; while(i >= 0 && j < y) { s = s + array[i][j]; i--; j++; } if(s.find(word)!= string::npos) return true; // diagonally: /down s = ""; i = m; j = n; while(i < x && j >= 0) { s = s + array[i][j]; i++; j--; } if(s.find(word)!= string::npos) return true; // diagonally: up s = ""; i = m; j = n; while(i >= 0 && j >= 0) { s = s + array[i][j]; i--; j--; } if(s.find(word)!= string::npos) return true; // diagonally: \down s = ""; i = m; j = n; while(i < x && j < y) { s = s + array[i][j]; i++; j++; } if(s.find(word)!= string::npos) return true; return false; }