짱아의 개발 기록장

2018 KAKAO BLIND RECRUITMENT : 프렌즈4 블록(c++) / 구현 본문

Algorithm/카카오 기출

2018 KAKAO BLIND RECRUITMENT : 프렌즈4 블록(c++) / 구현

jungahshin 2021. 3. 10. 21:45
반응형

그냥 간단한 구현 문제였다.

코드를 참고하는 것이 좋겠다.

 

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
#include <string>
#include <vector>
#include <iostream>
#include <cstring>
#include <queue>
 
using namespace std;
 
int solution(int m, int n, vector<string> board) {
    int answer = 0;
    int num = n*m;
    
    while(num!=0){
        num = 0;
        int check[31][31= {0, };
        for(int i=0; i<=m-2; i++){
            for(int j=0; j<=n-2; j++){
                if(board[i][j] != '.' && board[i][j] == board[i][j+1&& board[i][j+1== board[i+1][j] && board[i+1][j] == board[i+1][j+1]){
                    check[i][j] = 1;
                    check[i+1][j] = 1;
                    check[i][j+1= 1;
                    check[i+1][j+1= 1;
                }
            }
        }
        
        for(int i=0; i<n; i++){ // 열
            queue<char> q;
            for(int j=m-1; j>=0; j--){ // 행
                if(check[j][i]==1){
                    num++;
                    continue;
                }
                q.push(board[j][i]);
            }
            
            for(int j=m-1; j>=0; j--){
                if(!q.empty()){
                    char c = q.front();
                    q.pop();
                    board[j][i] = c;
                    continue;
                }
                board[j][i] = '.';
            }
        }
        
        answer += num;
    }
 
    
    return answer;
}
cs
반응형
Comments