TOPIC

5% erro???

Anduin 110 asked 4 months ago

include

main () { int N, M, i, j, p = 0; while (scanf ("%d %d", &N, &M) != EOF){ int vet[N][M];

    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++){
            scanf ("%d", &vet[i][j]);
            if (vet[i][j] == 1) vet[i][j] = 9; 
            }

    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
                if (vet[i][j] != 9) {
                    if (i > 0) if (vet[i-1][j] == 9) p++;
                    if (i < N) if (vet[i+1][j] == 9) p++;
                    if (j > 0) if (vet[i][j-1] == 9) p++; 
                    if (j < M) if (vet[i][j+1] == 9) p++; 
                    vet[i][j] = p;
                    p = 0;
                }               

    for (i = 0; i < N; i++, printf ("\n"))
        for (j = 0; j < M; j++)
            printf ("%d", vet[i][j]);

        }

}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 4 months ago

    int N, M, i, j, p = 0; while (scanf ("%d %d", &N, &M) != EOF){ int vet[N][M];

    It should be

    int N, M, i, j; while (scanf ("%d %d", &N, &M) != EOF){ int vet[N][M], p = 0;