UVa 784 Maze Exploration(DFS)

这道题比较难办的是输入,有空格,要用gets();然后就是本小妞有马虎了,多写了一个else,结果半天没有音讯!还有就是,使得这个点不超范围,范围是要用&&来判断的,今天耍小聪明||了一下果断错了!

然后‘-’和‘_',减号和下划线今天还打混了!!!这些都要注意了

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

const int N = 100;
int T, sx, sy;
int a[] = { 0, 0, 1, -1 };
int b[] = { 1, -1, 0, 0 };
int cnt = 0, end = 0;
char g[N][N];

void dfs( int x, int y ) {
    g[x][y] = '#';
    for ( int i = 0; i < 4; ++i ) {
        int xx = x + a[i], yy = y + b[i];
        if ( ( xx >= 0 && xx < cnt - 1 ) && ( y >= 0 && y < strlen(g[xx]) ) && ( g[xx][yy] == ' ' || g[xx][yy] == '_' ) ) dfs ( xx, yy );
    }
}
int main()
{
    scanf("%d", &T);
    getchar();
    while ( T-- ) {
        memset( g, '\0', sizeof(g));
        cnt = end = 0;
        while ( gets( g[cnt] ) ) {
            end = 1;
            for ( int i = 0; i < strlen(g[cnt]); ++i ) { 
                if ( g[cnt][i] != '_' ) end = 0;
                if ( g[cnt][i] == '*' ) {
                    sx = cnt, sy = i;
                }
            }
            cnt++;
            if ( end == 1 ) break;
        }
        dfs( sx, sy );
        for ( int i = 0; i < cnt; ++i ) printf("%s\n", g[i]);
    }
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值