Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define TF 100
- int numBombas(char mat[TF][TF], int l, int c, int m, int n);
- void printaMatriz(char mat[TF][TF], int m, int);
- int main()
- {
- char mat[TF][TF];
- int m, n, cont = 0, l, c;
- scanf("%d %d", &m, &n);
- while(m > 0 && n > 0)
- {
- for(l = 0; l < m; l++)
- for(c = 0; c < n; c++)
- {
- fflush(stdin);
- scanf("%c", &mat[l][c]);
- }
- cont++;
- printf("Field #%d\n", cont);
- printaMatriz(mat, m, n);
- printf("\n");
- scanf("%d %d", &m, &n);
- }
- }
- int numBombas(char mat[TF][TF], int l, int c, int m, int n)
- {
- int cont = 0;
- if(l > 0)
- {
- if(mat[l - 1][c] == '*')
- cont++;
- if(c > 0)
- if(mat[l - 1][c - 1] == '*')
- cont++;
- if(c < n - 1)
- if(mat[l - 1][c + 1] == '*')
- cont++;
- }
- if(l < m - 1)
- {
- if(mat[l + 1][c] == '*')
- cont++;
- if(c > 0)
- if(mat[l + 1][c - 1] == '*')
- cont++;
- if(c < n - 1)
- if(mat[l + 1][c + 1] == '*')
- cont++;
- }
- if(c > 0)
- if(mat[l][c - 1] == '*')
- cont++;
- if(c < n - 1)
- if(mat[l][c + 1] == '*')
- cont++;
- return cont;
- }
- void printaMatriz(char mat[TF][TF], int m, int n)
- {
- int l, c;
- for(l = 0; l < m; l++)
- {
- for(c = 0; c < n; c++)
- if(mat[l][c] != '*')
- printf("%d", numBombas(mat, l, c, m, n));
- else
- printf("*");
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement