https://programmers.co.kr/learn/courses/30/lessons/64061
문제
입력&출력
문제해석
2차원 배열이 주어짐.
다음과 같이 적재됨. moves의 순서대로 인형을 뽑음. 배열로 따지면 moves[n]-1
1) 인형을 뽑으면 해당칸은 0 처리해준다.
2) 바구니는 후입선출 이므로 vector로 처리해준다. 같은 인형을 만났을때 vector.pop_back 해주며
3) 최종값에서 x2 해준다.
난이도
★☆☆☆☆
실수
X
스스코드
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(vector<vector<int>> board, vector<int> moves)
{
int answer = 0;
vector<int> buket;
for (int i = 0; i < moves.size(); i++)
{
int tempInt;
tempInt = moves[i]-1;
for (int j = 0; j < board[tempInt].size(); j++)
{
if (board[j][tempInt] != 0)
{
//if (buket.back() == board[j][tempInt] && buket.size() >= 1)
if (buket.size()>=1)
{
if (buket.back() == board[j][tempInt])
{
buket.pop_back();
answer++;
board[j][tempInt] = 0;
break;
}
}
buket.push_back(board[j][tempInt]);
board[j][tempInt] = 0;
break;
}
else
{
}
}
}
answer = answer * 2;
return answer;
}
int main()
{
solution({ { 0, 0, 0, 0, 0 }, {0, 0, 1, 0, 3 }, {0, 2, 5, 0, 1}, {4, 2, 4, 4, 2}, {3, 5, 1, 3, 1}}, { 1, 5, 3, 5, 1, 2, 1, 4 });
return 0;
}
'Algorithm' 카테고리의 다른 글
[백준11559 ]C++ Puyo Puyo (0) | 2020.07.11 |
---|---|
[프로그래머스] 키패드 누르기 (0) | 2020.07.05 |
[프로그래머스Lv3] 네트워크 (0) | 2020.07.05 |
[프로그래머스Lv3] 이중우선순위큐 C++ (0) | 2020.07.05 |
[백준 1706] 크로스워드 (C++, Java) (0) | 2020.07.05 |