求助,pts33!(壶关)
查看原帖
求助,pts33!(壶关)
995569
xibaby楼主2025/2/1 22:06
#include<bits/stdc++.h>
using namespace std;
char c[11][11]; int xc,yc,cx,xf,yf,fx;
int main(){
    for(int i=1;i<11;i++)
      for(int j=1;j<11;j++){
          scanf("%c",&c[i][j]);
          if(c[i][j]=='C') xc=i,yc=j;
          if(c[i][j]=='F') xf=i,yf=j;
      }
    for(int i=1;i<10001;i++){
        if(cx==0)
          if(c[xc-1][yc]=='.') xc--;
          else cx=(cx+1)%4;
        else if(cx==1)
          if(c[xc][yc+1]=='.') yc++;
          else cx=(cx+1)%4;
        else if(cx==2)
          if(c[xc+1][yc]=='.') xc++;
          else cx=(cx+1)%4;
        else
          if(c[xc][yc-1]=='.') yc--;
          else cx=(cx+1)%4;
        if(fx==0)
          if(c[xf-1][yf]=='.') xf--;
          else fx=(fx+1)%4;
        else if(fx==1)
          if(c[xf][yf+1]=='.') yf++;
          else fx=(fx+1)%4;
        else if(fx==2)
          if(c[xf+1][yf]=='.') xf++;
          else fx=(fx+1)%4;
        else
          if(c[xf][yf-1]=='.') yf--;
          else fx=(fx+1)%4;
        if(xc==xf&&yc==yf){
            printf("%d",i);
            return 0;
        }
    }
    printf("0");
    return 0;
}
2025/2/1 22:06
加载中...