满江红,大佬求调!!
查看原帖
满江红,大佬求调!!
1230697
EasyRememberName楼主2024/8/17 00:57

样例过但0 pts ,求调

#include<iostream>
using namespace std;
char a[505][505];
int n,m,sum=0;
int fun(int i,int j)
{
	if(i==1)
	{
		if(j!=1&&j!=m)
		{
			if(a[i-1][j]=='*'&&a[i][j+1]=='*'&&a[i][j-1]=='*')
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		else
		{
			if(j==1)
			{
				if(a[i-1][j]=='*'&&a[i][j+1]=='*')
				{
					return 1;
				}
				else
				{
					return 0;
				}
			}
			else
			{
				if(a[i-1][j]=='*'&&a[i][j-1]=='*')
				{
					return 1;
				}
				else
				{
					return 0;
				}
			}
		}
	}
	else
	{
		if(i==n)
		{
			if(j!=1&&j!=m)
			{
				if(a[i+1][j]=='*'&&a[i][j+1]=='*'&&a[i][j-1]=='*')
				{
					return 1;
				}
				else
				{
					return 0;
				}
			}
			else
			{
				if(j==1)
				{
					if(a[i+1][j]=='*'&&a[i][j+1]=='*')
					{
						return 1;
					}
					else
					{
						return 0;
					}
				}
				else
				{
					if(a[i+1][j]=='*'&&a[i][j-1]=='*')
					{
						return 1;
					}
					else
					{
						return 0;
					}
				}
			}
		}
		else
		{
			if(a[i+1][j]=='*'&&a[i-1][j]=='*'&&a[i][j+1]=='*'&&a[i][j-1]=='*')
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
	}
}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(a[i][j]=='0')
			{
				if(fun(i,j)==1)
				{
					sum++;
				}
			}	
		}
	}
	cout<<sum;
	return  0;
}
2024/8/17 00:57
加载中...