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 | 29 | 30 |
Tags
- NRVO
- winapi
- Unreal Engine5
- C++
- Frustum
- algorithm
- baekjoon
- GeeksForGeeks
- 팰린드롬 만들기
- 프로그래머스
- 오블완
- directx
- RootMotion
- 1563
- 백준
- UnrealEngine5
- IFileDialog
- Programmers
- softeer
- 줄 세우기
- UE5
- 티스토리챌린지
- RVO
- TObjectPtr
- 2294
- DirectX11
- C
- 언리얼엔진5
- const
- UnrealEngine4
Archives
- Today
- Total
Game Develop
[Algorithm] Programmers :: 택배상자 본문
https://school.programmers.co.kr/learn/courses/30/lessons/131704
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
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
29
30
31
32
33
34
35
36
37
38
39
40
|
int solution(vector<int> order)
{
int answer = 0;
stack<int> sub;
int curBoxNum = 1; // 컨베이어벨트에서 꺼낼 수 있는 상자.
int orderIndex = 0;
while (1)
{
if (orderIndex >= order.size() - 1) orderIndex = order.size() - 1;
if (order[orderIndex] > curBoxNum)
{
sub.push(curBoxNum);
++curBoxNum;
continue;
}
if (curBoxNum == order[orderIndex])
{
++curBoxNum;
++orderIndex;
++answer;
continue;
}
if (order[orderIndex] < curBoxNum)
{
if (sub.size() > 0 && sub.top() == order[orderIndex])
{
sub.pop();
++answer;
++orderIndex;
}
else break;
}
}
return answer;
}
|
cs |
음... 의외로 좀 걸렸던 문제. 실제 코딩테스트였다면 진짜 큰일날 뻔 했다.
'Algorithm > Programmers' 카테고리의 다른 글
[Algorithm] Programmers :: 우박수열 정적분 (0) | 2023.06.08 |
---|---|
[Algorithm] Programmers :: 롤케이크 자르기 (0) | 2023.06.08 |
[Algorithm] Programmers :: 연속 부분 수열 합의 개수 (0) | 2023.06.07 |
[Algorithm] Programmers :: 혼자 놀기의 달인 (0) | 2023.06.07 |
[Algorithm] Programmers :: 양궁대회 (1) | 2023.06.06 |