프로그래머스 64061 크레인 인형뽑기 게임

1 개요[ | ]

프로그래머스 64061 크레인 인형뽑기 게임

2 C++[ | ]

#include <string>
#include <vector>
#include <stack>
using namespace std;

int solution(vector<vector<int>> board, vector<int> moves) {
    stack<int> s;
    int h = board.size();
    int pick, y, answer = 0;
    for(const auto& move: moves) {
        pick = 0;
        for(y=0; y<h; y++) {
            pick = board[y][move-1];
            if(pick != 0) break;
        }
        if(pick == 0) continue;
        s.push(pick);
        board[y][move-1] = 0;
        while(true) {
            if(s.size()<2) break;
            int temp = s.top();
            s.pop();
            if(temp == s.top()) {
                s.pop();
                answer +=2;
            } else {
                s.push(temp);
                break;
            }
        }
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}