-
Notifications
You must be signed in to change notification settings - Fork 0
/
사탕 게임.cpp
115 lines (107 loc) · 1.92 KB
/
사탕 게임.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
using namespace std;
int checkBoard(char **board, int n)
{
int count = 0;
int tempCount;
for (int i = 0; i < n; i++) //세로 체크
{
char first;
int j = 0;
while (j != n - 1)
{
first = board[j][i];
tempCount = 1;
for (int k = j + 1; k < n; k++)
{
if (first == board[k][i])
tempCount++;
else
break;
}
if (tempCount > count)
count = tempCount;
j++;
}
}
for (int i = 0; i < n; i++) //가로
{
char first;
int j = 0;
while (j != n - 1)
{
first = board[i][j];
tempCount = 1;
for (int k = j + 1; k < n; k++)
{
if (first == board[i][k])
tempCount++;
else
break;
}
if (tempCount > count)
count = tempCount;
j++;
}
}
return count;
}
void toTempBoard(char **tempBoard, char **board, int n)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
tempBoard[i][j] = board[i][j];
}
}
int main(void)
{
int n;
cin >> n;
int count = 0;
char **board = new char* [n];
char **tempBoard = new char* [n];
for (int i = 0; i < n; i++)
{
board[i] = new char[n];
tempBoard[i] = new char[n];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cin >> board[i][j];
}
toTempBoard(tempBoard, board, n);
for (int i = 0;i < n - 1; i++)
{
for (int j = 0; j < n; j++)
{
toTempBoard(tempBoard, board, n);
if (board[i][j] != board[i + 1][j])
{
tempBoard[i][j] = board[i + 1][j];
tempBoard[i + 1][j] = board[i][j];
int tempCount = checkBoard(tempBoard, n);
if (tempCount > count)
count = tempCount;
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - 1; j++)
{
toTempBoard(tempBoard, board, n);
if (board[i][j] != board[i][j + 1])
{
tempBoard[i][j] = board[i][j + 1];
tempBoard[i][j + 1] = board[i][j];
int tempCount = checkBoard(tempBoard, n);
if (tempCount > count)
count = tempCount;
}
}
}
cout << count;
return 0;
}