Face Detection

来源:互联网 发布:哪个数据库有引文检索 编辑:程序博客网 时间:2024/06/11 20:05

Description

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 a2 × 2 square, 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 andm (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively.

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

Output

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

Sample Input

Input
4 4xxxxxfaxxcexxxxx
Output
1
Input
4 2xxcfaexx
Output
1
Input
2 3faccef
Output
2
Input
1 4face
Output
0

Sample Output

Hint

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.







#include <stdio.h>#include <stdlib.h>int main(){    int n, m, i, j, x = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s = 0;    char a[100][100];    scanf("%d%d", &n, &m);    getchar();    for (i = 0; i < n; i++)    {        for (j = 0; j < m; j++)        {            scanf("%c", &a[i][j]);        }        getchar();    }    for (i = 0; i < n; i++)    {        for (j = 0; j < m; j++)        {            s1 = 0; s2 = 0; s3 = 0; s4 = 0;            if (a[i][j] == 'f' || a[i][j + 1] == 'f' || a[i + 1][j] == 'f' || a[i + 1][j + 1] == 'f' && i + 1 < n && j + 1 < m)            {                s1++;            }            if (a[i][j] == 'a' || a[i][j + 1] == 'a' || a[i + 1][j] == 'a' || a[i + 1][j + 1] == 'a' && i + 1 < n && j + 1 < m)            {                s2++;            }            if (a[i][j] == 'c' || a[i][j + 1] == 'c' || a[i + 1][j] == 'c' || a[i + 1][j + 1] == 'c' && i + 1 < n && j + 1 < m)            {                s3++;            }            if (a[i][j] == 'e' || a[i][j + 1] == 'e' || a[i + 1][j] == 'e' || a[i + 1][j + 1] == 'e' && i + 1 < n && j + 1 < m)            {                s4++;            }            if (s1 > 0 && s2 > 0 && s3 > 0 && s4 > 0)                s++;        }    }    printf("%d\n", s);    return 0;}


0 0
原创粉丝点击