Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. bool String_compare(char string_1[90900], char string_2[90900])
  4. {
  5.  
  6. int i = 0;
  7.  
  8. while (string_1[i] != '\0' && string_2[i] != '\0')
  9. {
  10. if (string_1[i] != string_2[i])
  11. return false;
  12. else
  13. i++;
  14.  
  15. }
  16. return true;
  17. }
  18.  
  19.  
  20.  
  21.  
  22. int count_ways(char grid[30][30][101], int current_row, int current_column, char word_matrix[900][100], int word_count, int word_index)
  23. {
  24. if (!strcmp(grid[current_row][current_column], word_matrix[word_index]))
  25. {
  26. if (word_count == word_index)return 1;
  27. else return count_ways(grid, current_row + 1, current_column, word_matrix, word_count, word_index+1) +
  28. count_ways(grid, current_row - 1, current_column, word_matrix, word_count, word_index+1) +
  29. count_ways(grid, current_row, current_column + 1, word_matrix, word_count, word_index+1) +
  30. count_ways(grid, current_row, current_column - 1, word_matrix, word_count, word_index+1);
  31. }
  32. else return 0;
  33. }
  34.  
  35.  
  36. int countReads(char grid[30][30][101], int gridRows, int gridColumns, char sentence[90001])
  37. {
  38.  
  39. char word_matrix[900][100];
  40. int index = 0;
  41. int i = 0;
  42. int j = 0;
  43.  
  44. while (sentence[index] != '\0')
  45. {
  46. if (sentence[index] != ' ')
  47. {
  48. word_matrix[i][j] = sentence[index];
  49. j++;
  50. }
  51. else
  52. {
  53. word_matrix[i][j] = '\0';
  54. i++;
  55. j = 0;
  56. }
  57. index++;
  58. }
  59.  
  60. int count = 0;
  61.  
  62. for (int n = 0; n < gridRows; n++)
  63. {
  64. for (int m = 0; m < gridColumns; m++)
  65. {
  66. count += count_ways(grid, n, m, word_matrix, i, 0);
  67. }
  68.  
  69. }
  70.  
  71. return count;
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement