1768.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 85 行

CPP
85
字号
/*  This Code is Submitted by wywcgs for Problem 1768 on 2005-09-16 at 23:43:41 */ 
#include <stdio.h>

int main()
{
    int n, num[11][11];
    int i, j, touchMine, k = 0;
    char touched[11][11];
    
    while(scanf("%d", &n) == 1) {
        if(k != 0) {
            putchar('\n');
        }    
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                num[i][j] = 0;
            }
        }
        while(getchar() != '\n')
            ;
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                if(getchar() == '*') {
                    if(i > 0) {
                        if(j > 0) {
                            num[i-1][j-1]++;
                        }    
                        num[i-1][j]++;
                        if(j < n-1) {
                            num[i-1][j+1]++;
                        }    
                    }
                    if(i < n-1) {
                        num[i+1][j]++;
                        if(j < n-1) {
                            num[i+1][j+1]++;
                        }    
                    } 
                    if(j < n-1) {   
                        num[i][j+1]++;
                    }    
                    if(j > 0) {
                        num[i][j-1]++;
                        if(i < n-1) {
                            num[i+1][j-1]++;
                        }    
                    }
                    num[i][j] = -50;
                }    
            }
            while(getchar() != '\n')
                ;
        }
        touchMine = 0;
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                if(getchar() == 'x') {
                    touched[i][j] = 1;
                    if(num[i][j] < 0) {
                        touchMine = 1;
                    }    
                } else {
                    touched[i][j] = 0;
                }    
            }
            while(getchar() != '\n')
                ;
        }
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                if(touchMine && (num[i][j] < 0)) {
                    putchar('*');
                } else if(touched[i][j]) {
                    printf("%d", num[i][j]);
                } else {
                    putchar('.');
                }
            }
            putchar('\n');
        }
        k++;
    }
    
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?