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
imported>Unknown
No edit summary
 
(Repair batch-0002 pages from live compare)
Line 1: Line 1:
= MineSweeper =
= MineSweeper =
==  
==  
~cpp MineSweeper.cpp
<code>MineSweeper.cpp</code>
==
==
  #include&lt;iostream&gt;
  #include&lt;iostream&gt;
Line 16: Line 16:
  count++;
  count++;
 
 
  char* temp=new char[width];
  char* temp=new char&#91;width&#93;;
  int* arrayOfMine=new int[width*height];
  int* arrayOfMine=new int&#91;width*height&#93;;
 
 
  for(int a=0;a&lt;height;a++)
  for(int a=0;a&lt;height;a++)
  for(int b=0;b&lt;width;b++)
  for(int b=0;b&lt;width;b++)
  arrayOfMine[a*width+b]=0;
  arrayOfMine&#91;a*width+b&#93;=0;
 
 
  for(int i=0;i&lt;height;i++)
  for(int i=0;i&lt;height;i++)
Line 28: Line 28:
  for(int j=0;j&lt;width;j++)
  for(int j=0;j&lt;width;j++)
  {
  {
  if(temp[j]=='*')
  if(temp&#91;j&#93;=='*')
  {
  {
  if(i&gt;0 &amp;&amp; j&gt;0)
  if(i&gt;0 &amp;&amp; j&gt;0)
  arrayOfMine[(i-1)*width+(j-1)]++;
  arrayOfMine&#91;(i-1)*width+(j-1)&#93;++;
  if(j&gt;0)
  if(j&gt;0)
  arrayOfMine[(i)*width+(j-1)]++;
  arrayOfMine&#91;(i)*width+(j-1)&#93;++;
  if(i&lt;height-1 &amp;&amp; j&gt;0)
  if(i&lt;height-1 &amp;&amp; j&gt;0)
  arrayOfMine[(i+1)*width+(j-1)]++;
  arrayOfMine&#91;(i+1)*width+(j-1)&#93;++;
  if(i&gt;0)
  if(i&gt;0)
  arrayOfMine[(i-1)*width+(j)]++;
  arrayOfMine&#91;(i-1)*width+(j)&#93;++;
  if(i&lt;height-1)
  if(i&lt;height-1)
  arrayOfMine[(i+1)*width+(j)]++;
  arrayOfMine&#91;(i+1)*width+(j)&#93;++;
  if(i&gt;0 &amp;&amp; j&lt;width-1)
  if(i&gt;0 &amp;&amp; j&lt;width-1)
  arrayOfMine[(i-1)*width+(j+1)]++;
  arrayOfMine&#91;(i-1)*width+(j+1)&#93;++;
  if(j&lt;width-1)
  if(j&lt;width-1)
  arrayOfMine[(i)*width+(j+1)]++;
  arrayOfMine&#91;(i)*width+(j+1)&#93;++;
  if(i&lt;height-1 &amp;&amp; j&lt;width-1)
  if(i&lt;height-1 &amp;&amp; j&lt;width-1)
  arrayOfMine[(i+1)*width+(j+1)]++;
  arrayOfMine&#91;(i+1)*width+(j+1)&#93;++;
  arrayOfMine[i*width+j]=BOMB;
  arrayOfMine&#91;i*width+j&#93;=BOMB;
  }
  }
  }
  }
Line 56: Line 56:
  for(int x=0;x&lt;width;x++)
  for(int x=0;x&lt;width;x++)
  {
  {
  if(arrayOfMine[y*width+x]&gt;=BOMB)
  if(arrayOfMine&#91;y*width+x&#93;&gt;=BOMB)
  cout&lt;&lt;"*";
  cout&lt;&lt;"*";
  else
  else
  cout&lt;&lt;arrayOfMine[y*width+x];
  cout&lt;&lt;arrayOfMine&#91;y*width+x&#93;;
   
   
  }
  }
Line 65: Line 65:
  }
  }
  }
  }

Revision as of 00:16, 27 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;
	}
}