30分求助,没有测试点好痛苦
查看原帖
30分求助,没有测试点好痛苦
785140
perfectbit222楼主2022/10/2 15:32
#include<iostream>
using namespace std;
int main()
{
	int r, c, k, g = 0, ans = 0;
	char a;
	cin >> r >> c >> k;
	int p[100][100];
	for (int b = 1; b <= r; b++)//录入数组 
	{
		for (int d = 1; d <= c; d++)
		{
			cin >> a;
			if (a == '.')
			{
				p[b][d] = 1;
			}
			if (a == '#')
			{
				p[b][d] = 2;
			}
		}
	}
	for (int b = 1; b <= r; b++)//读取数组 b==y,d==x
	{
		for (int d = 1; d <= c; d++)//b == y d == x
		{
			if (p[b][d] == 1)//可以继续读取 
			{
				//if ((r - b) >= k)
				//{
					for (int x = 0; x < k; x++)//横向搜索 
					{
						if (p[b][d+x] == 1)
						{
							g++;
						}
					}
					if (g == k)
					{
						ans++;
					}
					g = 0;
				//}
				//if ((c - d) >= k)
				//{

					for (int y = 0; y < k; y++)//纵向搜索 
					{
						if (p[b+y][d] == 1)
						{
							g++;
						}
					}
					if (g == k)
					{
						ans++;
					}
					g = 0;
				//}
			}
		}
	}
	cout << ans;
}
2022/10/2 15:32
加载中...