Advertisement
Guest User

Palude

a guest
Aug 28th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define ROWS 5
  4. #define COLS 11
  5. #define FALSE 0
  6. #define TRUE 1
  7.  
  8. #define FREE '*'
  9.  
  10. void printMatrix(char matrix[ROWS][COLS]);
  11.  
  12. int hasPath(char matrix[ROWS][COLS]) {
  13.  
  14.     printf("\n # Looking for paths in:\n");
  15.     printMatrix(matrix);
  16.  
  17.     int r, c;
  18.  
  19.     for (r = 0; r < ROWS; r++) {
  20.         int tmp_r = r;
  21.         for (c = 0; c < COLS; c++) {
  22.  
  23.             if (c == COLS - 1)
  24.                 return TRUE;
  25.  
  26.             if (matrix[tmp_r][c] != FREE)
  27.                 if (matrix[tmp_r + 1][c] == FREE)
  28.                     tmp_r++;
  29.                 else if (matrix[tmp_r - 1][c] == FREE)
  30.                     tmp_r--;
  31.                 else
  32.                     break;
  33.  
  34.         }
  35.     }
  36.  
  37.  
  38.     return FALSE;
  39. }
  40.  
  41. void printMatrix(char matrix[ROWS][COLS]) {
  42.     int r, c;
  43.     for (r = 0; r < ROWS; r++) {
  44.         printf("\n");
  45.         for (c = 0; c < COLS; c++)
  46.             printf("%c ", matrix[r][c]);
  47.     }
  48. }
  49.  
  50. int main() {
  51.     char palude_yes[ROWS][COLS] =
  52.             {
  53.                     "**.*.*....*",
  54.                     "..*.*...**.",
  55.                     "*...*.*....",
  56.                     ".*.*.*.*.*.",
  57.                     "..*.*...*.*"
  58.             };
  59.  
  60.     char palude_no[ROWS][COLS] =
  61.             {
  62.                     "**.*.*.....",
  63.                     "..*.*...*..",
  64.                     "*...*.*....",
  65.                     ".*.*.*.*...",
  66.                     "..*.*...*.."
  67.             };
  68.  
  69.     if (hasPath(palude_yes) == TRUE) {
  70.         printf("\n\nYES");
  71.     } else {
  72.         printf("\n\nNO");
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement