其他分享
首页 > 其他分享> > 随手练——C语言网-1096: Minesweeper

随手练——C语言网-1096: Minesweeper

作者:互联网

题目链接:http://www.dotcpp.com/oj/problem1096.html

#include <iostream>
#include <string.h>
using namespace std;
char M[105][105];

void DFS(int i, int j) {
    if (M[i][j] == '.' || M[i][j] == '*') {
        if (M[i][j] == '.') {
            int count = 0;
            for (int a = i - 1; a <= i + 1; a++) {
                for (int b = j - 1; b <= j + 1; b++) {
                    if (M[a][b] == '*')count++;
                }
            }
            M[i][j] = count + '0';
        }
        DFS(i + 1, j);
        DFS(i, j + 1);
    }
}
int main() {
    int m, n, k = 1;
    while (cin >> m >> n) {
        if (m == 0 || n == 0)break;
        cin.ignore();
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                char c = getchar();
                M[i][j] = c;
            }
            getchar();
        }
        DFS(1, 1);
        cout << "Field #" << k++ << ":" << endl;
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                cout << M[i][j];
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

 

标签:1096,cin,int,Minesweeper,www,C语言,include,105
来源: https://www.cnblogs.com/czc1999/p/10382840.html