A. Face Detection

来源:互联网 发布:淘宝开通信用卡 编辑:程序博客网 时间:2024/04/29 20:15

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.

In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2square, such that from the four letters of this square you can make word "face".

You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.

Input

The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively.

Next n lines define the image. Each line contains m lowercase Latin letters.

Output

In the single line print the number of faces on the image.

Sample test(s)
input
4 4xxxxxfaxxcexxxxx
output
1
input
4 2xxcfaexx
output
1
input
2 3faccef
output
2
input
1 4face
output
0
Note

In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:

In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.

In the third sample two faces are shown:

In the fourth sample the image has no faces on it.


解题说明:此题是一道图形题,要求找出图中所有包含F‘a’c‘e这四个字母的2*2的矩形。最简单的方法是暴力穷举,遍历整个图,然后进行判断统计。注意边界情况即可。


#include <stdio.h>int n,m,i,j,t,d1,d2,d3,d4,k,l;char a[105][105];int main(){scanf("%d%d",&n,&m);for(i=0;i<n;i++){scanf("%s",a[i]);}for(i=0;i<n-1;i++){for(j=0;j<m-1;j++){d1=d2=d3=d4=0;for(k=0;k<2;k++){for(l=0;l<2;l++){if(a[i+k][j+l]=='f'){d1=1;}if(a[i+k][j+l]=='a'){d2=1;}if(a[i+k][j+l]=='c'){d3=1;}if(a[i+k][j+l]=='e'){d4=1;}}}if(d1&&d2&&d3&&d4){t++;}}}printf("%d\n",t);return 0;}


0 0