头文件
C++#include<bits/stdc++.h>
using namespace std;
int main(){
return 0;
}
资料
LATEX格式大全
Markdown格式
luogu工具
C++#include<bits/stdc++.h>
using namespace std;
int ax[]={1,-1,0,0,1,-1,1,-1};
int bx[]={0,0,-1,1,-1,-1,1,1};
int main(){
int leishu,bianchang;
cout<<"请输入地图边长,不要太大(Please cin map`s long , not too big):";
cin>>bianchang;
bool leishuflag=true;
while(leishuflag){
cout<<"\n请输入雷的数量(Please cin bad grounds number):";
cin>>leishu;
if(leishu>=bianchang*bianchang||leishu<=0){
cout<<"\n数字不对,请重输(It is not a good number , please cin again):";
}
else{
leishuflag=false;
}
}
int n=leishu,m=bianchang,t=m+1;
int mp[t][t];
char cl[t][t];
string jl[t][t];
int seed;
cout<<"\n请输入随机数种子(Please cin a rand seed to srand):";
cin>>seed;
srand(seed);
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
mp[i][j]=0;
jl[i][j]="空";
cl[i][j]='X';
}
}
for(int i=1;i<=n;i++){
int x,y;
x=rand()%bianchang;
y=rand()%bianchang;
if(mp[x][y]==0){
mp[x][y]=1;
jl[x][y]="雷";
}
else{
i--;
continue;
}
}
bool ying=true;
int sc=0,cd=0,bjd=0;
while(ying||cd!=m*m-n||bjd!=n){
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
cout<<cl[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
int x,y,xs;
bool cmp=true;
while(cmp){
cout<<"\n你要的位置(Please cin your map[x][y]):";
cin>>x>>y;
x-=1;y-=1;
cout<<"\n输入操作:操作0为猜,操作1为标记,操作2为删除标记(Cin TODO : TODO 0 is guess , TODO 1 is paint , TODO 2 is unpaint):";
cin>>xs;
if(x>=m||y>=m||xs>2||xs<0){
cout<<"\n数字不对,请重输(It is not a good number , please cin again):";
}
else{
cmp=false;
}
}
if(xs==0){
if(mp[x][y]==1){
ying=false;
break;
}
else{
int cls=0;
for(int i=0;i<8;i++){
if(mp[x+ax[i]][y+bx[i]]==1){
cls++;
}
}
sc+=cls;
cl[x][y]=char(cls+48);
cd++;
}
}
else if(xs==1){
if(mp[x][y]==1){
sc++;
bjd++;
}
cl[x][y]='9';
}
else{
cl[x][y]='0';
bjd--;
}
}
if(ying)cout<<"\n你赢了(You are wing)";
else cout<<"\n你炸了(You are lose)";
cout<<endl<<"\n成绩(Score):"<<sc<<endl<<endl;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
cout<<jl[i][j]<<" ";
}
cout<<endl;
}
return 0;
}