개발 로그/알고리즘
크레인 인형뽑기 c++풀이
k._.
2021. 8. 23. 07:49
#include <string>
#include <vector>
using namespace std;
int solution(vector<vector<int>> board, vector<int> moves) {
int answer = 0;
vector <int> container;
int temp =0;
for(int m = 0; m<moves.size(); m++){
for(int i = 0; i<board.size(); i++){
if(board[i][moves[m]-1] != 0){
temp = board[i][moves[m]-1];
board[i][moves[m]-1] = 0;
if(container.empty())
container.push_back(temp);
else{
if(container.back()==temp){
answer+=2;
container.pop_back();
}
else
container.push_back(temp);
}
break;
}
}
}
return answer;
}