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

MineSweeper/곽세환

From ZeroWiki
Revision as of 00:16, 27 March 2026 by Maintenance script (talk | contribs) (Repair batch-0002 pages from live compare)

MineSweeper 문제풀이


소감

지뢰찾기 겜 만든 경험을 바탕으로 바로 짰음 문제푸는데 30분 + 문제제출하는데 30분 VC++에선 컴파일에러 안 났는데 문제채점하는곳에선 에러 변수 i 선언 밖으로 빼고, main이 int리턴하도록 변경해서 해결 그래도 프레젠테이션 에러는 발생 왜 그럴까나...

소스

#include <iostream>
using namespace std;

// 주위에 있는 지뢰의 수를 찾는다.
int findNumberOfMine(char input[][100], int n, int m, int y, int x)
{
	int number = 0;
	for (int i = y - 1; i <= y + 1; i++)
		for (int j = x - 1; j <= x + 1; j++)
		{
			if (i >= 0 && i < n && j >= 0 && j < m && input[i][j] == '*')
				number++;
		}
	return number;
}

int main()
{
	int n, m;
	int field = 0;
	char input[100][100];
	char output[100][100];
	cin >> n >> m;
	field++;
	int i, j;
	while (!(n == 0 && m == 0))
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < m; j++)
			{
				cin >> input[i][j];
			}
		for (i = 0; i < n; i++)
			for (j = 0; j < m; j++)
			{
				if (input[i][j] == '*')
					output[i][j] = '*';
				else
					output[i][j] = findNumberOfMine(input, n, m, i, j) + '0';
			}

		cout << "Field #" << field << ":\n";
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < m; j++)
				cout << output[i][j];
			cout << endl;
		}
		cout << endl;
		cin >> n >> m;
		field++;
	}
	return 0;
}

MineSweeper