Notice
Recent Posts
Recent Comments
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
- 백준 5397
- Stack 이란
- C/C++ 구현
- c#
- 구현
- 해시구현
- 백준
- 버킷 정렬
- 백준 17779
- 5397
- AVL 시간 복잡도
- 백준 1406
- 백준 2447
- qorwns
- 게리멘더링2
- 자료구조
- 조세퍼스 순열
- 스택의 특징
- 별 찍기 10
- 해시 구현
- 원판 돌리기
- dfs
- 백준 17471
- heap
- 풀이
- 시간 복잡도
- ㅣ풀이
- 백준 17822
- 백준 1158
- 1764
Archives
- Today
- Total
홍시홍의 프로그래밍
[프로그래머스] 크레인 인형뽑기 본문
분류 : 구현
요구사항
stack 활용하여 문제가 끝난 후, 사라진 인형의 수 구하기
풀이
함정없는 단순 구현 문제이다
문제에 제시된 조건대로 구현하면 된다
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int map[35][35];
int boardr = 0;
int boardc = 0;
int solve(vector<int> move) {
vector<int> v;
int cnt = 0;
for (int i = 0; i < move.size(); i++) {
int nowc = move[i];
int r = 0;
for (r = 1; r <= boardr; r++) {
if (map[r][nowc] != 0) {
int temp = map[r][nowc];
map[r][nowc] = 0;
if (!v.empty()) {
int nowvalue = v.back();
if (temp == nowvalue) {
v.pop_back();
cnt++;
cnt++;
}
else {
v.push_back(temp);
}
}
else {
v.push_back(temp);
}
break;
}
}
}
return cnt;
}
//board 2차원 배열, moves는 이동 배열
int solution(vector<vector<int>> board, vector<int> moves) {
int answer = 0;
boardr = board.size();
boardc = board[0].size();
//init
for (int i = 0; i < board.size(); i++) {
for (int j = 0; j < board[i].size(); j++) {
map[i+1][j+1] = board[i][j];
}
}
answer = solve(moves);
return answer;
}
'알고리즘 문제풀이 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 멀쩡한 사각형 (0) | 2020.04.05 |
---|---|
[프로그래머스] 쇠막대기 (0) | 2020.04.03 |
[프로그래머스] 디스크 컨트롤러 (0) | 2020.03.30 |
[프로그래머스] 라면공장 (0) | 2020.03.30 |
[프로그래머스] 더 맵게 (0) | 2020.03.30 |
Comments