U E D R , A S I H C RSS

Minesweeper/이도현

2006-01-03 05:40:25 Accepted 0.012 Minimum 56031 C++ 10189 - Minesweeper

.
2 8 .
100 x 100 .
-.-;;

Presentation Error . .
. 한 해 .
.
if outputNumber > 1 Presentation Error .

~cpp
// Minesweeper
// UVa ID : 10189
// 2    (1,1)  .
#include <iostream>
//#include <fstream>
using namespace std;
#define ArSize 102

void process(char data[][ArSize], int row, int col);
void init_array(char data[][ArSize], int row, int col);
void output(char data[][ArSize], int row, int col);

//ifstream fin("input.txt");

int main()
{
	char data[ArSize][ArSize];
	int inputRow, inputCol;
	int outputNumber = 1;
	int i, j;
	
	while (cin >> inputRow >> inputCol)
	{
		// 
		if ((inputRow == 0) && (inputCol == 0))
			break;

		//  화 ( '.' 화)
		init_array(data, inputRow + 1, inputCol + 1);

		//  (1,1)  .
		for (i = 1; i <= inputRow; i++)
		{
			for (j = 1; j <= inputCol; j++)
			{
				cin >> data[i][j];
			}
		}

		//   
		process(data, inputRow, inputCol);

		//  (     !!)
		if (outputNumber > 1)
			cout << endl;
		cout << "Field #" << outputNumber++ << ":" << endl;
		output(data, inputRow, inputCol);
	}

	return 0;
}

void process(char data[][ArSize], int row, int col)
{
	int i, j;
	char count = '0';
	
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			//  pass
			if (data[i][j] == '*')
				continue;
			else
			{
				// 
				if (data[i - 1][j - 1] == '*')
					count++;

				// 
				if (data[i - 1][j] == '*')
					count++;

				// 
				if (data[i - 1][j + 1] == '*')
					count++;

				// 
				if (data[i][j + 1] == '*')
					count++;

				// 
				if (data[i + 1][j + 1] == '*')
					count++;

				// 
				if (data[i + 1][j] == '*')
					count++;

				// 
				if (data[i + 1][j - 1] == '*')
					count++;

				// 
				if (data[i][j - 1] == '*')
					count++;

				data[i][j] = count;
				count = '0';
			}
		}
	}
}

//  화
void init_array(char data[][ArSize], int row, int col)
{
	int i, j;
	
	for (i = 0; i <= row; i++)
	{
		for (j = 0; j <= col; j++)
		{
			data[i][j] = '.';
		}
	}
}

//  -   
void output(char data[][ArSize], int row, int col)
{
	int i, j;
	
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			cout << data[i][j];
		}
		cout << endl;
	}
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:46
Processing time 0.0144 sec