https://www.acmicpc.net/problem/17608
아이디어:
1. 우선 스택에 다 넣고, 마지막부터 비교하면서 뺀다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, tmp, ans = 0;
stack<int> S;
cin >> N;
while (N--) {
cin >> tmp;
S.push(tmp);
}
tmp = S.top();
while (!S.empty()) {
if (S.top() > tmp) {
tmp = S.top();
ans += 1;
}
S.pop();
}
cout << ans + 1;
return 0;
}
'algorithm' 카테고리의 다른 글
백준 12789번 도키도키 간식드리미 (0) | 2025.02.23 |
---|---|
백준 1935번 후위 표기식2, C++ 소수점 출력 (0) | 2025.02.22 |
백준 12605번 단어순서 뒤집기, C++ stringstream으로 문자열 공백 기준 자르기 (0) | 2025.02.17 |
백준 1874번 스택 수열 (1) | 2025.02.16 |
백준 12891번 DNA 비밀번호 (0) | 2024.12.15 |