• + 0 comments
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    void cavityMap(int n,char** grid){
        for(int i=1;i<n-1;i++){
            for(int j=1;j<n-1;j++){
                if(grid[i][j]>grid[i][j-1]&&grid[i][j]>grid[i][j+1]&&grid[i][j]>grid[i-1][j]&&grid[i][j]>grid[i+1][j]){
                    grid[i][j]='X';
                }
            }
        }
        for(int i=0;i<n;i++){
            printf("%s\n", grid[i]);
        }
    }
    
    int main()
    {
        int n;
        scanf("%d",&n);
        char** grid=(char**)malloc(n*sizeof(char*));
        for(int i=0;i<n;i++)
        {
            grid[i]=(char*)malloc((n+1)*sizeof(char));
            scanf("%s",grid[i]);
        }
        cavityMap(n,grid);
        for(int i=0;i<n;i++)
            free(grid[i]);
        free(grid);
        return 0;
    }