Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ROWS 5
- #define COLS 11
- #define FALSE 0
- #define TRUE 1
- #define FREE '*'
- void printMatrix(char matrix[ROWS][COLS]);
- int hasPath(char matrix[ROWS][COLS]) {
- printf("\n # Looking for paths in:\n");
- printMatrix(matrix);
- int r, c;
- for (r = 0; r < ROWS; r++) {
- int tmp_r = r;
- for (c = 0; c < COLS; c++) {
- if (c == COLS - 1)
- return TRUE;
- if (matrix[tmp_r][c] != FREE)
- if (matrix[tmp_r + 1][c] == FREE)
- tmp_r++;
- else if (matrix[tmp_r - 1][c] == FREE)
- tmp_r--;
- else
- break;
- }
- }
- return FALSE;
- }
- void printMatrix(char matrix[ROWS][COLS]) {
- int r, c;
- for (r = 0; r < ROWS; r++) {
- printf("\n");
- for (c = 0; c < COLS; c++)
- printf("%c ", matrix[r][c]);
- }
- }
- int main() {
- char palude_yes[ROWS][COLS] =
- {
- "**.*.*....*",
- "..*.*...**.",
- "*...*.*....",
- ".*.*.*.*.*.",
- "..*.*...*.*"
- };
- char palude_no[ROWS][COLS] =
- {
- "**.*.*.....",
- "..*.*...*..",
- "*...*.*....",
- ".*.*.*.*...",
- "..*.*...*.."
- };
- if (hasPath(palude_yes) == TRUE) {
- printf("\n\nYES");
- } else {
- printf("\n\nNO");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement