알고리즘/BOJ(백준)
[ 백준-1874번 / 스택 ] 스택 수열
by 뎁꼼
2020. 3. 3.
1. 문제
2. 소스코드
#include <iostream>
#include <stack>
//#include <vector>
using namespace std;
int n, index = 1;
stack <int> seq;
//vector <char> ans;
string ans;
int main() {
cin >> n;
//for (int i = 0; i < n; i++)
while(n--){
int num;
cin >> num;
while (index <= num){
//seq.push(index);
//index++;
seq.push(index++);
ans += '+';
}
if (!seq.empty()) {
if (num == seq.top()) {
seq.pop();
ans += '-';
}
else {
cout << "NO";
return 0;
}
}
//else break;
}
for (char ch : ans) {
cout << ch << '\n';
}
return 0;
}