两个样例自己测试都过了但全wa,求各位大佬看看
  • 板块P1101 单词方阵
  • 楼主Ryoo
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/18 09:45
  • 上次更新2024/5/18 11:51:17
查看原帖
两个样例自己测试都过了但全wa,求各位大佬看看
1100140
Ryoo楼主2024/5/18 09:45
//教训:处理输入时要注意换行符的处理,必要时使用getchar()过滤换行 

#include <bits/stdc++.h>
using namespace std;
int n,dir[9][2] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}},tempx = 0,tempy = 0,dircon = 0;
char a[105][105],b[105][105],c[8] = "yizhong";

void dfs(int t,int x,int y) {
	if(dircon == 8) {		//全部的方向搜索完成 
	
		dircon = 0;return;
	}
	
	
	
	if(t == 6) {		//找到符合的字符串 
		
		int tx = tempx,ty = tempy;
		
		for(int i = 0; i <= 6; i++) {		//染色 
			b[ty][tx] = a[ty][tx];
		
			ty += dir[dircon][1];tx += dir[dircon][0];
		}
		dircon += 1;
		dfs(0,tempx,tempy);		//换向继续查找 
	}
	else{
		if(a[y+dir[dircon][1]][x+dir[dircon][0]] == c[t+1]) {		//下一位字符符合条件且没有越界 
			dfs(t+1,x+dir[dircon][0],y+dir[dircon][1]);
		}
		else {		//没有符合条件,换向继续查找 
			dircon++;
			dfs(0,tempx,tempy);
		}
	}
	
}
int main() {
	scanf("%d", &n);
	getchar();			//接收多出来的一个空格 
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			scanf("%c", &a[i][j]);
			
		}
		getchar();
	} 
		
	//printf("%s", c);
	for(int i = 1; i <= n; i++)			//全部先赋值为‘*’ 
		for(int j = 1; j <= n; j++) 
			{
				b[i][j] = '*';
				if(a[i][j] == '\0') a[i][j] = 'w';
			}
			
			
	
		
	
			
	for(int i = 1; i <= n; i++) {		//若找到'y', 进行全部方向的查找 
		for(int j = 1; j <= n; j++) {
			if(a[i][j] == 'y') {
				tempx = j;tempy = i;
				dfs(0,tempx,tempy);
			}
		}
	}
	
	for(int i = 1; i <= n; i++) {		//输出结果 
		for(int j = 1; j <= n; j++) {
			printf("%c", b[i][j]);
		}
		printf("\n");		//把最后一个换行过滤掉 
	}	
	return 0;
}
2024/5/18 09:45
加载中...