260318 TIL - 챕터4 멀티플레이어 게임 개발 8일차

2026. 3. 18. 21:09언리얼 7기 본캠프

과제 버닝기간이라 코드카타 푼 문제로 대신함

#include <string>
#include <vector>

using namespace std;

int solution(int m, int n, vector<string> board) {
    int answer = 0;
    int currentanswer = -1;
    while(currentanswer != answer)
    {
        currentanswer = answer;
        vector<vector<bool>> issquared(m, vector<bool>(n));
        
        for(int i = 0; i < m - 1; i++)
        {
            for(int j = 0; j < n - 1; j++)
            {
                if (board[i][j] == 'X') continue;
                if (board[i][j] == board[i + 1][j] &&
                    board[i][j] == board[i][j + 1] &&
                    board[i][j] == board[i + 1][j + 1])
                {
                    issquared[i][j] = true;
                    issquared[i + 1][j] = true;
                    issquared[i][j + 1] = true;
                    issquared[i + 1][j + 1] = true;
                }
            }
        }
        
        for(int i = 0; i < m; i++)
        {
            for(int j = 0; j < n; j++)
            {
                if (issquared[i][j])
                {
                    answer++;
                    board[i][j] = 'X';
                }
            }
        }
        
        for(int j = 0; j < n; j++)
        {
            int bottom = -1;
            for(int i = m - 1; i >= 0; i--)
            {
                if(board[i][j] == 'X' && i > bottom) bottom = i;
                if(board[i][j] != 'X' && i < bottom)
                {
                    board[bottom][j] = board[i][j];
                    board[i][j] = 'X';
                    bottom--;
                }
            }
        }
    }
    return answer;
}