题解 P1234 【小A的口头禅】
这道题···也是十分的简单呢。 ——唳
首先列举一下本蒟蒻发现的坑坑:
1.找的是hehe而不是he
亲测,没有什么阔以讲的呢。。。
2.斜着的hehe不算
水淋淋友好的样例告诉大家,斜着的hehe是莫得灵魂的。
3.正着的和反着的hehe都算,自上而下或自下而上的hehe也算。
hehe,eheh都算,
h e
e h
h e
e h 也是算的,所以上下左右都要搜de。
废话好像有点多,直接为各位dalao奉上AC代码
AC代码
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int ans,n,m;
char c[1100][1100];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>c[i][j];//把所有字符输入;
if(c[i][j]=='h') if(c[i][j-1]=='e'&&c[i][j-2]=='h'&&c[i][j-3]=='e') ans++;//向左先搜一次;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(c[i][j]=='h')
{
if(c[i][j+1]=='e'&&c[i][j+2]=='h'&&c[i][j+3]=='e') ans++;//向右再搜一次;
if(c[i-1][j]=='e'&&c[i-2][j]=='h'&&c[i-3][j]=='e') ans++;//向上再搜一次;
if(c[i+1][j]=='e'&&c[i+2][j]=='h'&&c[i+3][j]=='e') ans++;//最后再向下搞一次,完事;
}
}
}
cout<<ans<<endl;
return 0;
}
蒟蒻第一篇题解,求过QAQ