문제풀이/백준

3085 - 사탕 게임

동바리 2021. 6. 22. 23:13
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int check(const vector<string>& str)
{
int length = str.size();
int ans = 1;
for(int i = 0; i < length; i++) {
int cnt = 1;
for(int j = 1; j < length; j++) {
if(str[i][j - 1] == str[i][j]) {
cnt += 1;
} else {
cnt = 1;
}
if(ans < cnt) {
ans = cnt;
}
}
cnt = 1;
for(int j = 1; j < length; j++) {
if(str[j - 1][i] == str[j][i]) {
cnt += 1;
} else {
cnt = 1;
}
if(ans < cnt) {
ans = cnt;
}
}
}
return ans;
}
int main(void)
{
int length = 0;
cin >> length;
vector<string> str(length);
for(int i = 0; i < length; i++) {
cin >> str[i];
}
int ans = 0;
for(int i = 0; i < length; i++) {
for(int j =0; j < length; j++) {
if(j + 1 < length) {
swap(str[i][j], str[i][j + 1]);
int temp = check(str);
if(ans < temp) {
ans = temp;
}
swap(str[i][j], str[i][j + 1]);
}
if(i + 1 < length) {
swap(str[i][j], str[i + 1][j]);
int temp = check(str);
if(ans < temp) {
ans = temp;
}
swap(str[i][j], str[i+1][j]);
}
}
}
cout << ans << '\n';
return 0;
}
view raw 3085.cpp hosted with ❤ by GitHub