八十分求助
查看原帖
八十分求助
527772
Login_楼主2021/8/6 16:09
#include<iostream>
#include<string>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int n,m;
string str[100];

int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>str[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int count=0;
			if(i-1>=0&&str[i-1][j]=='*') count++;
			if(i+1<m&&str[i+1][j]=='*') count++;
			if(j-1>=0&&str[i][j-1]=='*') count++;
			if(j+1<m&&str[i][j+1]=='*') count++;			
			if(i-1>=0&&j-1>=0&&str[i-1][j-1]=='*') count++;
			if(i-1>=0&&j+1<m&&str[i-1][j+1]=='*') count++;
			if(i+1<m&&j-1>=0&&str[i+1][j-1]=='*') count++;
			if(i+1<m&&j+1<m&&str[i+1][j+1]=='*') count++;
			
			if(str[i][j]=='*') cout<<'*';
			else cout<<count;
		}
		if(i!=n-1) cout<<endl;
	}
	return 0;
}
2021/8/6 16:09
加载中...