BOJ 1874 스택 수열 c++
백준 1874 스택 수열 cpp
#include <bits/stdc++.h>
using namespace std;
stack<int> S;
int arr[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int ea;
cin >> ea;
int mx = 0;
for (int i = 0; i < ea; i++) {
cin >> arr[i];
if (arr[i] > mx) {
mx = arr[i];
continue;
}
else {
if (arr[i] > arr[i-1]){
cout << "NO";
return 0;
}
}
}
int i = 1;
S.push(0);
int cur = 0;
while (true) {
if (S.top() < arr[cur]) {
S.push(i++);
cout << "+\n";
continue;
}
else if (S.top() == arr[cur]) {
cout << "-\n";
cur++;
S.pop();
if (cur == ea)
break;
}
}
}
최근댓글