标签:algorithm 技术分享 技术 end tps 问题 cout 分享 window
扫雷是Windows自带的游戏。游戏的目标是尽快找到雷区中的所有地雷,而不许踩到地雷。如果方块上的是地雷,将输掉游戏。如果方块上出现数字,则表示在其周围的八个方块中共有多少颗地雷。
你的任务是在已知地雷出现位置的情况下,得到各个方块中的数据。
*... .... “*”表示有地雷 .*.. “.”表示无地雷 ....
经过处理应得到
*100 2210 1*10 1110
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int moves[8][2]={-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};
typedef struct
{
char c;
int num;
}booms;
int main()
{
int r,c;
while(cin>>r>>c)
{
if(r==0||c==0)
break;
booms mps[r+2][c+2];
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
cin>>mps[i][j].c;
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
{
int tx,ty;
int tmp=0;
for(int k=0;k<8;k++)
{
tx=i+moves[k][0];
ty=j+moves[k][1];
if(mps[tx][ty].c==‘*‘)
tmp++;
}
mps[i][j].num=tmp;
}
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
if(mps[i][j].c==‘*‘)
cout<<"*";
else
cout<<mps[i][j].num;
}
cout<<endl;
}
cout<<endl;
}
}
此代码某些地方存在问题,大体思想是正确的。
标签:algorithm 技术分享 技术 end tps 问题 cout 分享 window
原文地址:http://www.cnblogs.com/masterchd/p/6772457.html