Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 17608번 막대기 본문
조금만 입체적으로 생각하면 되는 문제이다.
stack의 선입선출의 구조를 생각하면 되는 문제인데,
단순히 마지막에 있는 막대기보다 큰 막대기를 세는 것이 아니라
막대기의 앞뒤를 비교하면 쉽게 풀 수 있다.
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n;
cin >> n;
stack<int> st;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
st.push(x);
}
int temp = st.top();
int count = 1;
while (!st.empty()) {
if (st.top() > temp) {
temp = st.top();
count++;
}
st.pop();
}
cout << count << "\n";
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 10799번 쇠막대기 (0) | 2021.08.02 |
|---|---|
| [C++] 백준 17952번 과제는 끝나지 않아! (0) | 2021.08.02 |
| [C++] 백준 1436번 영화감독 숌 (0) | 2021.07.23 |
| [C++] 백준 2749번 피보나치 수 3 (0) | 2021.07.23 |
| [C++] 백준 9471번 피사노 주기 (0) | 2021.07.23 |
Comments