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;
}
'알고리즘 > BOJ(백준)' 카테고리의 다른 글
[ 백준-13023번 / 그래프 ] ABCDE (0) | 2020.03.08 |
---|---|
[ 백준-17299번 / 스택 ] 오등큰수 (0) | 2020.03.05 |
[ 백준-17298번 / 스택 ] 오큰수 (0) | 2020.03.05 |
[ 백준-10799번 / 스택 ] 쇠막대기 (0) | 2020.03.04 |
[ 백준-17413번 / 스택 ] 단어 뒤집기2 (0) | 2020.03.04 |