U E D R , A S I H C RSS

minesweeper/Celfin

~cpp
#include <iostream>
using namespace std;

char mine[102][102];
int x, y, i, j;
int field=0;
int blank=0;

void SearchMine()
{
	for(i=1; i<y+1; i++)
	{
		for(j=1; j<x+1; j++)
		{
			if(mine[j][i]!='*')
			{
				mine[j][i]=48;
				if(mine[j-1][i-1]=='*')
					mine[j][i]++;
				if(mine[j-1][i]=='*')
					mine[j][i]++;
				if(mine[j-1][i+1]=='*')
					mine[j][i]++;
				if(mine[j][i+1]=='*')
					mine[j][i]++;
				if(mine[j+1][i+1]=='*')
					mine[j][i]++;
				if(mine[j+1][i]=='*')
					mine[j][i]++;
				if(mine[j+1][i-1]=='*')
					mine[j][i]++;
				if(mine[j][i-1]=='*')
					mine[j][i]++;
			}
		}
	}
}

void Print()
{
	field++;
	cout << "Field #"<<field<<":"<<endl;
	for(i=1; i<y+1; i++)
	{
		for(j=1; j<x+1; j++)
			cout<<mine[j][i];
		cout<<endl;
	}	
}

int main()
{
	while(cin>>y>>x)
	{
		if(x==0 && y==0)
			break;
		for(i=0; i<y+2; i++)
			for(j=0; j<x+2; j++)
				mine[j][i]='.';
		for(i=1; i<y+1; i++)
			for(j=1; j<x+1; j++)
				cin>>mine[j][i];
		SearchMine();
		if(blank++!=0)
			cout << endl;
		Print();
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:43
Processing time 0.0106 sec