ACM (UVa) : 10279


// http://uva.onlinejudge.org/external/102/10279.html

#include <stdio.h>

struct node {
    char mine;
    int number;
    char output;
} a [12] [12];

int n;

void constructor ()
{
    for ( int i = 0; i < 12; i++ )
        a [0] [i].mine = a [11] [i].mine = a [i] [0].mine = a [i] [11].mine = '.';

    for ( int i = 0; i < 12; i++ ) {
        for ( int j = 0; j < 12; j++ ) {
            a [i] [j].number = 0;
            a [i] [j].output = '.';
        }
    }
}

void increase (int x, int y)
{
    a [x - 1] [y].number++;
    a [x - 1] [y + 1].number++;
    a [x] [y + 1].number++;
    a [x + 1] [y + 1].number++;
    a [x + 1] [y].number++;
    a [x + 1] [y - 1].number++;
    a [x] [y - 1].number++;
    a [x - 1] [y - 1].number++;
}

void print_mine ()
{
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= n; j++ ) {
            if ( a [i] [j].mine == '*' )
                a [i] [j].output = '*';
        }
    }
}


int main ()
{
    int games;
    scanf ("%d", &games);

    bool blank = false;

    while ( games-- ) {

        if ( blank )
            printf ("\n");
        blank = true;

        constructor ();

        scanf ("%d", &n);
        getchar ();

        char input [12];

        // first block
        for ( int i = 0; i < n; i++ ) {
            gets (input);

            for ( int j = 0; j < n; j++ ) {
                a [i + 1] [j + 1].mine = input [j];
                if ( input [j] == '*' )
                    increase (i + 1, j + 1);
            }
        }

        // 2nd block
        bool mined = false;

        for ( int i = 0; i < n; i++ ) {
            gets (input);

            for ( int j = 0; j < n; j++ ) {
                if ( input [j] == 'x' ) {
                    if ( a [i + 1] [j + 1].mine == '*' )
                        mined = true;
                    else
                        a [i + 1] [j + 1].output = a [i + 1] [j + 1].number + '0';
                }
            }
        }

        if ( mined )
            print_mine ();

        // output
        for ( int i = 1; i <= n; i++ ) {
            for ( int j = 1; j <= n; j++ )
                printf ("%c", a [i] [j].output);
            printf("\n");
        }

    }

    return 0;
}

One thought on “ACM (UVa) : 10279

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s