스택의 원리만 알면 상당히 쉽다.
오른쪽에서 바라보고 있는 상황이므로 Last input값을 기준으로 계속해서 바라보고 있으므로 스택임을 추론할 수 있다.
추가적으로 마지막으로 바라본 것보다 더 큰 것만을 count를 올려주는 것이므로, 계속해서 pop시키면서 max값보다 크면 갯수를 올리고 max값을 업데이트시키면 된다.
해당하는 알고리즘으로 코드를 구현하면 다음과 같다.
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
int main(void){
int n;
cin >> n;
stack<int> stack_store;
for(int i = 0; i < n; i++){
int temp;
cin >> temp;
stack_store.push(temp);
} // data_store
int max = -1;
int count = 0;
for(int i = 0 ; i < n; i++){
int compare = stack_store.top();
if (compare > max){
count += 1;
max = compare;
}
stack_store.pop();
}
cout << count << "\n";
return 0;
}