문제출처 : https://www.acmicpc.net/problem/1874
code
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
int n, index = 0;
cin >> n;
vector<int>seq(n);
vector<int> v;
vector<char> cv;
for (int i = 0; i < n; i++)
cin >> seq[i];
for (int i = 0; i < n; i++)
{
v.push_back(i+1);
cv.push_back('+');
while (!v.empty() && v.back() == seq[index])
{
v.pop_back();
cv.push_back('-');
index++;
}
}
if (v.empty())
for (int i = 0; i < 2*n; i++)
cout << cv[i] << '\n';
else
cout << "NO";
return 0;
}
코드로 구현하는데 조금 애먹었다.. 왜캐헷갈리지