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.0110 sec