Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MineSweeper/김회영: Difference between revisions

From ZeroWiki
(Repair batch-0002 pages from live compare)
(Repair MoniWiki formatting after migration)
 
Line 1: Line 1:
= MineSweeper =
= [[MineSweeper]] =
==  
==  
<code>MineSweeper.cpp</code>
<code>MineSweeper.cpp</code>

Latest revision as of 00:34, 29 March 2026

MineSweeper

== MineSweeper.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;
	}
}