aa

· · 个人记录

#include <windows.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long
int x,y,xx,yy;
bool a[111][111];
void draw(int n,int m){

    a[x][y]=1;
    int q=rand()%(n+m)*5+1;
    aa:
    xx=x;
    yy=y;
    while(q--){
        int f=rand()%4+1,b=rand()%4+1;
        if(f==1){
            while(b--){
                xx++;
                if(xx>n||!xx||!yy||yy>m){
                    goto aa;
                }
                a[xx][yy]=1;
            }
        }
        if(f==2){
            while(b--){
                xx--;
                if(xx>n||!xx||!yy||yy>m){
                    goto aa;
                }
                a[xx][yy]=1;
            }
        }
        if(f==3){
            while(b--){
                yy++;
                if(xx>n||!xx||!yy||yy>m){
                    goto aa;
                }
                a[xx][yy]=1;
            }
        }
        if(f==4){
            while(b--){
                yy--;
                if(xx>n||!xx||!yy||yy>m){
                    goto aa;
                }
                a[xx][yy]=1;
            }
        }
    }
}
signed main(void){

    int n,m;
    cin>>n>>m;
    srand(time(0));
    x=rand()%n+1;
    y=rand()%m+1;
    xx=x;
    yy=y;
    draw(n,m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]==0){
                cout<<"墙"; 
            }else if(i==x&&j==y){
                cout<<"我";
            }else if(i==xx&&j==yy){
                cout<<"终";
            }else{
                cout<<"  ";
            }
        }
        cout<<'\n';
    }
    return 0;
}