P2670 [NOIP2015 普及组] 扫雷游戏
作者:互联网
题目链接
题目思路
模拟当前点的八个方向,扫描是否有雷
题目代码
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110;
char g[N][N];
int n, m;
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i ++ ) cin >> g[i];
int dx[8] = {-1, 0, 1, 0, -1, 1, -1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
for(int i = 0; i < n; i ++ )
{
for(int j = 0; j < m; j ++ )
{
int sum = 0;
for(int k = 0; k < 8; k ++ )
{
if(g[i][j] == '*')
{
cout << '*';
break;
}
int x = i + dx[k], y = j + dy[k];
if(x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '*') sum ++ ;
}
if(g[i][j] != '*') cout << sum;
}
puts("");
}
return 0;
}
标签:P2670,NOIP2015,题目,cout,int,sum,++,扫雷,&& 来源: https://www.cnblogs.com/vacilie/p/15983433.html