Description
In a BG (dinner gathering) for ZCMU ACM team, the coaches wanted to count the number of people present at the BG. They did that by having the waitress take a photo for them. Everyone in the photo, no one is blocked by others. Each person in the photo has the same posture. After some preprocessing, the photo was converted into a H×W character matrix, Thus a person in this photo is represented by the diagram in the following three lines:
.O.
/|\
(.)
Given the character matrix, the coaches want you to count the number of people in the photo. Note that if something is partly blocked in the photo, only part of the above diagram will be presented in the character matrix,good luck to you.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first contains two integers H, W (1 ≤ H, W ≤ 100) - as described above, followed by H lines, showing the matrix representation of the photo.
Output
For each test case, there should be a single line, containing an integer indicating the number of people from the photo.
Sample Input
1
3
3
.O.
/|\
(.)
Sample Output
1
解析
题目的意思就是让你找矩阵中有多少个小人
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,i,j;
char p[105][105];
int check()
{
int sum=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(p[i][j]=='O')
{
if(i+2<=n&&j-1>=1&&j+1<=m)
{
if(p[i+1][j]=='|'&&p[i+1][j-1]=='/'&&p[i+1][j+1]=='\\'&&p[i+2][j-1]=='('&&p[i+2][j+1]==')')
sum++;
}
}
}
}
return sum;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>p[i][j];
}
}
printf("%d\n",check());
}
return 0;
}