Advertisement
Guest User

safsa\sfd

a guest
Jan 19th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. void num_routes(char grid[30][30][101], int index_of_last, int index_of_current,
  2.     int grid_rows, int grid_cols,
  3.     int curr_row, int curr_col) {
  4.     //check if coordinates are correct
  5.     if (curr_row < 0 || curr_row > grid_rows || curr_col < 0 || curr_col > grid_cols) {
  6.         return;
  7.     }
  8.  
  9.     //at the last word
  10.     if (index_of_current == index_of_last && !strcmp(grid[curr_row][curr_col], sentence_to_words[index_of_last])) {
  11.         routes++;
  12.         return;
  13.     }
  14.     //current word isn't on your coordinates
  15.     if (strcmp(grid[curr_row][curr_col], sentence_to_words[index_of_current])) {
  16.         return;
  17.     }
  18.     //proceed till last word is found
  19.     else {
  20.         num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row + 1, curr_col);
  21.         num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row - 1, curr_col);
  22.         num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row, curr_col + 1);
  23.         num_routes(grid, index_of_last, index_of_current + 1, grid_rows, grid_cols, curr_row, curr_col - 1);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement