https://www.acmicpc.net/problem/1874
#include <stack>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> V(N);
for (int i = 0; i < N; ++i)
{
cin >> V[i];
}
stack<int> s;
vector<string> answers;
int top = 1;
int idx = 0;
while(idx < N)
{
if (s.empty() || V[idx] > s.top())
{
if (top <= N)
{
s.push(top++);
answers.push_back("+");
}
else
{
cout << "NO";
return 0;
}
}
else if (V[idx] == s.top())
{
s.pop();
answers.push_back("-");
++idx;
}
else
{
cout << "NO";
return 0;
}
}
for (string answer : answers)
{
cout << answer << "\n";
}
}
'코딩테스트' 카테고리의 다른 글
[프로그래머스] 롤케이크 자르기(C++) (0) | 2025.06.08 |
---|---|
[프로그래머스] 주식가격(C++) (0) | 2025.05.22 |
[백준] 온라인 저지 13414번 : 수강신청(C++), 해시맵 (0) | 2025.04.28 |
[백준] 온라인 저지 7785번 : 회사에 있는 사람(C++), 해시 (0) | 2025.04.21 |
[백준] 온라인 저지 18870번 : 좌표 압축(C++), 이분탐색 (0) | 2025.04.18 |