Last active
May 22, 2020 05:41
-
-
Save DongguemYoo/41e8e1424f2b4f5fdaf0741a715c4cf3 to your computer and use it in GitHub Desktop.
코딩테스트 연습 - 크레인 인형 뽑기(c++)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//보드쌓는 방식 x,y를 거꾸로 보고 해결하려고 해서 계속 에러가 | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int solution(vector<vector<int>> board, vector<int> moves) { | |
int answer = 0; | |
vector<int> result; | |
for(int i=0;i<moves.size();i++) | |
{ | |
for(int j=0;j<board.size();j++) | |
{ | |
if(board[j][moves[i]-1] == 0) | |
continue; | |
if(result.size()>0 && board[j][moves[i]-1] == result.back()) | |
{ | |
result.pop_back(); | |
answer++; | |
}else | |
result.push_back(board[j][moves[i]-1]); | |
board[j][moves[i]-1]=0; | |
break; | |
} | |
} | |
return answer*2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment