U E D R , A S I H C RSS

Mine Sweeper/김회영

~cpp MineSweeper.cpp

~cpp 
#include<iostream>
using namespace std;
#define BOMB 100
void main()
{
	int count=0;

	int width,height;
	
	cin>>height;
	cin>>width;
	count++;
	
	char* temp=new char[width];
	int* arrayOfMine=new int[width*height];
	
	for(int a=0;a<height;a++)
		for(int b=0;b<width;b++)
			arrayOfMine[a*width+b]=0;
	
	for(int i=0;i<height;i++)
	{	
		cin>>temp;
		for(int j=0;j<width;j++)
		{
			if(temp[j]=='*')
			{
				if(i>0 && j>0)
					arrayOfMine[(i-1)*width+(j-1)]++;
				if(j>0)
					arrayOfMine[(i)*width+(j-1)]++;
				if(i<height-1 && j>0)
					arrayOfMine[(i+1)*width+(j-1)]++;
				if(i>0)
					arrayOfMine[(i-1)*width+(j)]++;
				if(i<height-1)
					arrayOfMine[(i+1)*width+(j)]++;
				if(i>0 && j<width-1)
					arrayOfMine[(i-1)*width+(j+1)]++;
				if(j<width-1)
					arrayOfMine[(i)*width+(j+1)]++;
				if(i<height-1 && j<width-1)
					arrayOfMine[(i+1)*width+(j+1)]++;
				arrayOfMine[i*width+j]=BOMB;
			}
		}
	}

	cout<<endl<<"Field# :"<<count<<endl;
	for(int y=0;y<height;y++)
	{	
		for(int x=0;x<width;x++)
		{	
			if(arrayOfMine[y*width+x]>=BOMB)
				cout<<"*";
			else
				cout<<arrayOfMine[y*width+x];

		}
		cout<<endl;
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:46
Processing time 0.0096 sec