为什么用scanf过不了???

B3625 迷宫寻路

Qiu101029 @ 2024-04-04 20:43:31

scanf(70pts)

cin(AC)

求解答


by Qiu101029 @ 2024-04-04 20:48:34

这样应该不违规吧?


by Special_Tony @ 2024-04-04 20:50:18

@Qiu101029 发你代码


by Qiu101029 @ 2024-04-04 20:52:29

#include<cstdio>
using namespace std;
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
bool vis[105][105];
int n,m;
bool f;
char c;
void dfs(int x,int y){
    if(x==n&&y==m){
        f=true;
        return;
    }
    int xx,yy;
    vis[x][y]=true;
    for(int i=0;i<4;i++){
        xx=x+dx[i];
        yy=y+dy[i];
        if(xx<1||yy<1||xx>n||yy>m||vis[xx][yy]){
            continue;
        }
        dfs(xx,yy);
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%c",&c);
            if(c=='#'){
                vis[i][j]=true;
            }
        }
    }
    dfs(1,1);
    if(f){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

by Special_Tony @ 2024-04-04 20:54:13

@Qiu101029 记得直接读字符串,不然scanf读字符的时候是会把换行吃进来当字符的。。


by Qiu101029 @ 2024-04-04 20:54:31

@Special_Tony 你打不开链接吗?


by Qiu101029 @ 2024-04-04 20:58:38

@Special_Tony 好的,十分感谢


by yanhaoming @ 2024-06-23 14:30:08

可以用

scanf(" %c");

|