Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- VARCHAR (1)
- terminal
- 깡돼후
- 코루틴 컨텍스트
- k8s #kubernetes #쿠버네티스
- taint
- 달인막창
- pytest
- JanusWebRTC
- tolerated
- Value too long for column
- 자원부족
- 티스토리챌린지
- python
- Spring Batch
- JanusWebRTCGateway
- 개성국밥
- vfr video
- table not found
- 겨울 부산
- PersistenceContext
- 오블완
- JanusGateway
- JanusWebRTCServer
- PytestPluginManager
- preemption #
- 코루틴 빌더
- kotlin
- mp4fpsmod
Archives
너와 나의 스토리
[Programmers] 2019 카카오 개발자 겨울 인턴십 - 크레인 인형뽑기 게임 본문
반응형
문제: https://programmers.co.kr/learn/courses/30/lessons/64061
문제 풀이:
stack을 이용하여 쌓아 올리면 됨.
소스 코드:
#include <string>
#include <vector>
#include <stack>
using namespace std;
int cur[32];
stack<int> st;
int solution(vector<vector<int>> board, vector<int> moves) {
int answer = 0;
int row = board.size();
int col = board[0].size();
//init
for (int i = 0; i < col; i++) {
for (int j = 0; j <row; j++) {
if (board[j][i] != 0) {
cur[i] = j;
break;
}
}
}
for (int i = 0; i < moves.size(); i++) {
int curP = moves[i]-1;
if (cur[curP] >=row) continue;
if (st.empty()) {
st.push(board[cur[curP]][curP]);
}
else {
if (st.top() == board[cur[curP]][curP]) {
answer += 2;
st.pop();
}
else st.push(board[cur[curP]][curP]);
}
cur[curP]++;
}
return answer;
}
반응형
'Algorithm > 구현' 카테고리의 다른 글
[BOJ] 18809 Gaaaaaaaaaarden (0) | 2020.05.19 |
---|---|
[BOJ] 18808 스티커 붙이기 (0) | 2020.05.19 |
1770. [SW Test 샘플문제] 블록 부품 맞추기 (4) | 2019.11.07 |
[BOJ] 13567 로봇 (0) | 2019.10.04 |
(BOJ) 2933 미네랄 (0) | 2019.07.28 |
Comments