poj 1573(水题)

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
    int row,col,start,i,j,data[15][15],step,s1,s2;
    char c[15][15];
    bool flag;
    while(scanf("%d%d%d",&row,&col,&start)==3&&row){
        for(i=0;i<row;i++){
            scanf("%s",c[i]);
        }
        memset(data,0,sizeof(data));
        i = 0;j = start-1;
        step = 0;
        flag = false;
        while(true){
            if(i<0||i>=row||j<0||j>=col){
                break;
            }
            if(data[i][j]==0){
                data[i][j] = ++step;
                if(c[i][j]==N){
                    i--;
                }
                else if(c[i][j]==S){
                    i++;
                }
                else if(c[i][j]==W){
                    j--;
                }
                else if(c[i][j]==E){
                    j++;
                }
            }
            else{
                flag = true;
                s1 = step;
                s2 = data[i][j];
                break;
            }
        }
        if(flag)printf("%d step(s) before a loop of %d step(s)\n",s2-1,s1-s2+1);
        else printf("%d step(s) to exit\n",step);
    }
    return 0;
} 

 

poj 1573(水题)

上一篇:安装 pgadmin4 docker


下一篇:sys.excepthook