[洛谷]P1234 小A的口头禅 (#模拟)

题目描述

小A最近有了一个口头禅“呵呵”,于是他给出了一个矩形,让你求出里面有几个hehe(方向无所谓)。

输入输出格式

输入格式:

第一行两个数,n、m,表示这个矩形的大小。

以下n行,每行m的字符,表示这个矩形。

输出格式:

一行一个数,表示有几个hehe

输入输出样例

输入样例#1

5 5
heheh
heheh
heheh
heheh
heheh

输出样例#1

10

说明

1≤n,m≤1000

有1个点就是样例!


思路

直接模拟后面的数是不是“ehe”,注意斜着是不可以算作“hehe”的。

#include 
#include 
#include 
using namespace std;
int n,m,s;
char a[1002][1002];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	register int i,j,k;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(a[i][j]=='h')
			{
				if(a[i][j-1]=='e' && a[i][j-2]=='h' && a[i][j-3]=='e')
				{
					s++;
				}
				if(a[i][j+1]=='e' && a[i][j+2]=='h' && a[i][j+3]=='e')
				{
					s++;
				}
				if(a[i-1][j]=='e' && a[i-2][j]=='h' && a[i-3][j]=='e')
				{
					s++;
				}
				if(a[i+1][j]=='e' && a[i+2][j]=='h' && a[i+3][j]=='e')
				{
					s++;
				}
			}
		}
	}
	cout<

 

你可能感兴趣的:(洛谷原创,模拟)