1 条题解
-
-10
大部分应该是用8个if语句,这种应该简单吧
#include <bits/stdc++.h> using namespace std; int n,m; //定义方向数组 int dx[]={-1,-1,0,1,1,1,0,-1}; int dy[]={0,1,1,1,0,-1,-1,-1}; char a[105][105]; int main(){ cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];//读入数组; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(a[i][j]=='*') cout<< '*'; else{ int cnt=0;//表示雷数 for(int k=0;k<8;k++) { if(a[i+dx[k]][j+dy[k]]=='*')//核心代码:统计a[i][j]的上、下、左、右、左上、右上、左下、右下,是否有雷 cnt++; } cout<<cnt; } } cout<<endl; } return 0; }
- 1
信息
- ID
- 228
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 21
- 已通过
- 15
- 上传者