Tuesday, May 27, 2014

10189 - Minesweeper

#include <iostream>
using namespace std;
int main()
{
    int m,n,i,j,c,a=1;
    cin >> m >> n;
    while(1)
    {
        if(m==0 && n==0)
            break;
        char str[m+1][n+1];
        for(i=1; i<=m; i++)
            for(j=1; j<=n; j++)
                cin >> str[i][j];
        cout << "Field #" << a++ <<":\n";
        for(i=1; i<=m; i++)
        {
            for(j=1; j<=n; j++)
            {
                if(str[i][j]=='*')
                {
                    cout << "*";
                    continue;
                }
                c=0;
                if(i-1>0 && j-1>0)
                    if(str[i-1][j-1]== '*')
                        c++;
                if(i-1>0)
                    if(str[i-1][j]== '*')
                        c++;
                if(i-1>0 && j+1<=n)
                    if(str[i-1][j+1]== '*')
                        c++;
                if(j-1>0)
                    if(str[i][j-1]== '*')
                        c++;
                if(j+1<=n)
                    if(str[i][j+1]== '*')
                        c++;
                if(i+1<=m && j-1>0)
                    if(str[i+1][j-1]== '*')
                        c++;
                if(i+1<=m )
                    if(str[i+1][j]== '*')
                        c++;
                if(i+1<= m && j+1<=n)
                    if(str[i+1][j+1]== '*')
                        c++;
                cout << c ;
            }
            cout << endl;
        }
        cin >> m >> n;
        if(m!=0 && n!=0)
            cout << endl;
    }
    return 0;
}

No comments:

Post a Comment

Triathlon

Triathlon - CodeChef # include < bits/stdc++.h > using namespace std ; # define fi first # define se second # define mp ...