#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
stack<int> s;
int n;
string ans;
cin >> n;
int m = 0;
while (n--) {
int x;
cin >> x;
if (x > m) {
while (x > m) {
s.push(++m);
ans += '+';
}
s.pop();
ans += '-';
} else {
bool found = false;
if (!s.empty()) {
int top = s.top();
s.pop();
ans += '-';
if (x == top) {
found = true;
}
}
if (!found) {
cout << "NO" << '\n';
return 0;
}
}
}
for (auto x : ans) {
cout << x << '\n';
}
return 0;
}
'Algorithm > C++' 카테고리의 다른 글
[백준 1110번] 더하기 사이클 (0) | 2022.04.21 |
---|---|
[백준 17413번] 단어 뒤집기 2 (0) | 2022.04.19 |
[백준 5635번] 생일 (0) | 2022.04.09 |
[백준 9012] 괄호 (0) | 2022.04.08 |
[백준 9093] 단어 뒤집기 (0) | 2022.04.07 |
댓글