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