水题,暴力扫一遍就行
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
#define ll long long
#define maxn 100005
const int dx[4] = { 0, 0, 1, -1 };
const int dy[4] = { 1, -1, 0, 0 };
int N, M;
char grid[1005][1005];
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d%d", &N, &M);
for (int i = 0; i < N; ++i)
{
scanf("%s", grid[i]);
}
/*for (int i = 0; i < N; ++i)
{
printf("%s\n", grid[i]);
}*/
int sum = 0;
int x1, y1;
//bool flag = false;
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < M; ++j)
{
if (grid[i][j] != '+')
continue;
//flag = false;
for (int k = 0; k < 4; ++k)
{
x1 = i + dx[k];
y1 = j + dy[k];
if (x1 >= 0 && x1 < N&&y1 >= 0 && y1 < M)
{
//printf("%d %d\n", x1, y1);
if (grid[x1][y1] != '+')
{
//printf("1");
++sum;
break;
}
}
}
}
}
printf("%d\n", sum);
//system("pause");
//while (1);
return 0;
}