蒟蒻求助
查看原帖
蒟蒻求助
195432
極灬青龙楼主2020/8/11 15:33
#include <bits/stdc++.h>

using namespace std;

int n,sum,nn;
char m[1005][1005];

int hehe(int x,int y){
	int c = 0;
	if(x > 3){
		if(m[x - 1][y] == 'e'){
			if(m[x - 2][y] == 'h'){
				if(m[x - 3][y] == 'e'){
					c++;	
				}
			}
		}
	}
	if(x < n - 3){
		if(m[x + 1][y] == 'e'){
			if(m[x + 2][y] == 'h'){
				if(m[x + 3][y] == 'e'){
					c++;	
				}
			}
		}
	}
	if(y > 3){
		if(m[x][y - 1] == 'e'){
			if(m[x][y - 2] == 'h'){
				if(m[x][y - 3] == 'e'){
					c++;	
				}
			}
		}
	}
	if(y < nn - 3){
		if(m[x][y + 1] == 'e'){
			if(m[x][y + 2] == 'h'){
				if(m[x][y + 3] == 'e'){
					c++;	
				}
			}
		}
	}
//	printf("在第%d行第%d列有%d个hehe\n\n",x,y,c);
	return c;
}

int main(){
	scanf("%d%d",&n,&nn);
	getchar();
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= nn;j++){
			scanf("%c",&m[i][j]);
		}
		getchar(); 
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= nn;j++){
			if(m[i][j] == 'h'){
				sum += hehe(i,j);
			}
		}
	}
	printf("%d",sum);
	return 0;
}

自己在编译器上测的样例没有问题

交上去全是Wonderf Answer(WA)

2020/8/11 15:33
加载中...