Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void num_routes(char grid[30][30][101], int index_of_last, int index_of_current,
- int grid_rows, int grid_cols,
- int curr_row, int curr_col) {
- //check if coordinates are correct
- if (curr_row < 0 || curr_row > grid_rows || curr_col < 0 || curr_col > grid_cols) {
- return;
- }
- //at the last word
- if (index_of_current == index_of_last && !strcmp(grid[curr_row][curr_col], sentence_to_words[index_of_last])) {
- routes++;
- return;
- }
- //current word isn't on your coordinates
- if (strcmp(grid[curr_row][curr_col], sentence_to_words[index_of_current])) {
- return;
- }
- //proceed till last word is found
- else {
- num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row + 1, curr_col);
- num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row - 1, curr_col);
- num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row, curr_col + 1);
- num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row, curr_col - 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement