问题标题: 扫雷(不用**过关的都是大佬)

3
0
已解决
凌夏
凌夏
初级守护
初级守护

第一次发帖好开熏

难度一:5*5,2个雷

难度二:5*5,3个雷

难度三:6*6,5个雷

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<time.h>
#include<windows.h> 
using namespace std;
int f[100][100],g[100][100],cnt,vis[100][100],n,m,ans;
int main(){
    cout<<"扫雷\n";
    cout<<"输入:地图大小(n*n)     地雷个数"; 
    cin>>n>>m; 
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            f[i][j]=0;
        }
    }
    int t1;
    int t2;
    cout<<"加载地图,请等待......\n"; 
    for(int i=1;i<=m;i++){
        t1=rand()%5;
        Sleep(1000);
        t2=rand()%5;
        if(t1==0) t1=5;
        if(t2==0) t2=5;
        f[t1][t2]++;
        Sleep(1000);
        cout<<"加载完成";
        cout<<100/m*1.0*i;
        cout<<"%\n";
    }
    cout<<"加载完成!"; 
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int x=f[i-1][j]+f[i][j-1]+f[i+1][j]+f[i][j+1]+f[i-1][j-1]+f[i+1][j-1]+f[i+1][j+1]+f[i-1][j+1];
            g[i][j]=x;
            if(f[i][j]==0) ans++;
        }
    }
    /*for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<f[i][j]<<" "; 
        }
        cout<<endl;
    }*/
    //** 
    while(1){
        int x,y;
        cin>>x>>y;
        if(vis[x][y]){
            cout<<"不许重复走!太赖了吧你";
            continue; 
        }
        if(x>n || y>n || !x ||!y){
            cout<<"都走出地图了!(╯▔皿▔)╯";
            continue; 
        }
        if(f[x][y]==0){
            vis[x][y]=1;
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    if(i==x && j==y || vis[i][j]){
                        cout<<g[i][j]<<" ";
                    }else{
                        cout<<"? ";
                    }
                }
                cout<<endl;
            }
            cnt++;
            if(cnt==ans){
                cout<<"\n\n过关了!!\n\n";
            }
        }else{
            cout<<"踩雷了!轰!\n 成绩:";
            cout<<cnt;
            return 0;
        }
    }
} 

 


0
已采纳
李子墨
李子墨
新手天翼
新手天翼

@汪语成 扫雷大佬快快来

0
我要回答