竞赛讨论区 > 暴力求解
头像
牛客976772468号
发布于 2023-12-14 20:09
+ 关注

暴力求解

#include<iostream>

#include<cstdio>

using namespace std;

const int N=101;

char c[N][N];

int main()

{

int n,m;

cin>>n>>m;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

cin>>c[i][j];

for(int i=0;i<n;i++)

{

for(int j=0;j<m;j++)

{

if(c[i][j]=='*')cout<<c[i][j];

else{

int ans=8;

int l=j-1,r=j+1,s=i-1,x=i+1;

if(i==0||j==0||c[s][l]!='*')ans--;//左上

if(i==0||c[s][j]!='*')ans--;//上

if(i==0||j==m-1||c[s][r]!='*')ans--;//右上

if(j==0||c[i][l]!='*')ans--;//左

if(j==m-1||c[i][r]!='*')ans--;//右

if(j==0||i==n-1||c[x][l]!='*')ans--;//左下

if(i==n-1||c[x][j]!='*')ans--;//下

if(j==m-1||i==n-1||c[x][r]!='*')ans--;//右下

cout<<ans;

}

}

puts("");}

return 0;

}

全部评论

(0) 回帖
加载中...
话题 回帖

本文相关内容

等你来战

查看全部

热门推荐