안선생의 개발 블로그

백준 17608번 막대기 본문

백준

백준 17608번 막대기

안선생 2023. 2. 9. 14:53
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
#include <iostream>
#include <string>
#include<stack>
#include<vector>
using namespace std;
 
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    
    
    int n;
    stack<int> st;
    cin >> n;
    while (n--)
    {
        int a;
        cin>> a;
        st.push(a);
    }
 
    int count =1;
    int top = st.top();
    while (!st.empty())
    {
        if (top < st.top())
        {
            top = st.top();
            count++;
        }
        st.pop();
    }
    cout << count;
    return 0;
    
}
cs

https://www.acmicpc.net/problem/17608

 

17608번: 막대기

아래 그림처럼 높이만 다르고 (같은 높이의 막대기가 있을 수 있음) 모양이 같은 막대기를 일렬로 세운 후, 왼쪽부터 차례로 번호를 붙인다. 각 막대기의 높이는 그림에서 보인 것처럼 순서대로

www.acmicpc.net

 

'백준' 카테고리의 다른 글

C++ 13305 잃어버린 괄호  (0) 2023.02.10
C++ 11399 ATM  (0) 2023.02.10
C++ 11047 동전  (0) 2023.02.10
백준 11899 괄호 끼워넣기  (0) 2023.02.09
백준 1316  (0) 2023.01.20