比赛描述
输入
The first line of each case is two numbers N (1 <= N <= 100) .Then there will be a map contain N*N grids.The map is just contain O and X.'X' stands for a mine, 'O' stand for it is safe with nothing. You can assume there is at most one mine in one position. The last line of each case is two numbers X and Y(0<=X<N,0<=Y<N, indicating the position of the player's first touch.
输出
If the player touches the mine, just output "it is a beiju!".
If the player doesn't touch the mine, output the numbers appearing after the touch. If a position is touched by the player or by the computer automatically, output the number. If a position is not touched, output a dot '.'.
Output a blank line after each test case.
样例输入
5
OOOOO
OXXXO
OOOOO
OXXXO
OOOOO
1 1
5
OOOOO
OXXXO
OOOOO
OXXXO
OOOOO
0 0
样例输出
it is a beiju!
1....
.....
.....
.....
.....
题目来源
HDU OJ
#include<iostream> bool mine[100][100]; //地图上的这一点是否有地雷 char show[100][100]; //将要输出的数组 int N,i,j; bool is_mine(int i,int j){ if(i>=0 && i<N &&j>=0 &&j<N && mine[i][j]) return 1; else return 0; } void cal_show(int i,int j){ if(i<0 || i>=N || j<0 || j>=N || show[i][j] || is_mine(i,j)){ return; } if(is_mine(i-1,j-1)) ++show[i][j]; if(is_mine(i-1,j)) ++show[i][j]; if(is_mine(i-1,j+1)) ++show[i][j]; if(is_mine(i,j-1)) ++show[i][j]; if(is_mine(i,j+1)) ++show[i][j]; if(is_mine(i+1,j-1)) ++show[i][j]; if(is_mine(i+1,j)) ++show[i][j]; if(is_mine(i+1,j+1)) ++show[i][j]; show[i][j] += '0'; if(show[i][j]=='0'){ cal_show(i-1,j-1); cal_show(i-1,j); cal_show(i-1,j+1); cal_show(i,j-1); cal_show(i,j+1); cal_show(i+1,j-1); cal_show(i+1,j); cal_show(i+1,j+1); } } int main(){ while(scanf("%d",&N)!=EOF){ getchar(); for(i=0;i<N;++i){ for(j=0;j<N;++j){ show[0][0] = getchar(); if(show[0][0]=='O') mine[i][j] = 0; else mine[i][j] = 1; } getchar(); } scanf("%d%d",&i,&j); if(mine[i][j]){ printf("it is a beiju!\n\n"); }else{ memset(show,0,sizeof(show)); cal_show(i,j); for(i=0;i<N;++i){ for(j=0;j<N;++j){ if(show[i][j]) printf("%c",show[i][j]); else printf("."); } printf("\n"); } printf("\n"); } } }