More actions
imported>Unknown No edit summary |
(Repair MoniWiki formatting after migration) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
MineSweeper 문제풀이 | [[MineSweeper]] 문제풀이 | ||
---- | ---- | ||
== 소감 == | == 소감 == | ||
| Line 14: | Line 14: | ||
// 주위에 있는 지뢰의 수를 찾는다. | // 주위에 있는 지뢰의 수를 찾는다. | ||
int findNumberOfMine(char input | int findNumberOfMine(char input[][100], int n, int m, int y, int x) | ||
{ | { | ||
int number = 0; | int number = 0; | ||
| Line 20: | Line 20: | ||
for (int j = x - 1; j <= x + 1; j++) | for (int j = x - 1; j <= x + 1; j++) | ||
{ | { | ||
if (i >= 0 && i < n && j >= 0 && j < m && input | if (i >= 0 && i < n && j >= 0 && j < m && input[i][j] == '*') | ||
number++; | number++; | ||
} | } | ||
| Line 30: | Line 30: | ||
int n, m; | int n, m; | ||
int field = 0; | int field = 0; | ||
char input | char input[100][100]; | ||
char output | char output[100][100]; | ||
cin >> n >> m; | cin >> n >> m; | ||
field++; | field++; | ||
| Line 40: | Line 40: | ||
for (j = 0; j < m; j++) | for (j = 0; j < m; j++) | ||
{ | { | ||
cin >> input | cin >> input[i][j]; | ||
} | } | ||
for (i = 0; i < n; i++) | for (i = 0; i < n; i++) | ||
for (j = 0; j < m; j++) | for (j = 0; j < m; j++) | ||
{ | { | ||
if (input | if (input[i][j] == '*') | ||
output | output[i][j] = '*'; | ||
else | else | ||
output | output[i][j] = findNumberOfMine(input, n, m, i, j) + '0'; | ||
} | } | ||
| Line 55: | Line 55: | ||
{ | { | ||
for (j = 0; j < m; j++) | for (j = 0; j < m; j++) | ||
cout << output | cout << output[i][j]; | ||
cout << endl; | cout << endl; | ||
} | } | ||
| Line 66: | Line 66: | ||
---- | ---- | ||
[[MineSweeper]] | [[MineSweeper]] | ||
Latest revision as of 00:34, 29 March 2026
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;
}