[백준 1874번 C/C++] 스택 수열
목차
[백준 1874번 C/C++] 스택 수열
https://www.acmicpc.net/problem/1874
해결전략
Stack 사용
코드
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
stack<int> st;
vector<char> v;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
int n, input, num=0;
cin >> n;
st.push(num++);
for(int i=0; i<n; i++){
cin >> input;
while(true){
if (st.top() == input) break;
if(st.top()>input){
cout << "NO";
return 0;
}
st.push(num++);
v.push_back('+');
}
st.pop();
v.push_back('-');
}
for(const auto& i : v)
{
cout << i << "\n";
}
return 0;
}
'⭐ 코딩테스트 > 백준' 카테고리의 다른 글
[백준 11866번 C/C++] 요세푸스 문제 0 (0) | 2023.06.14 |
---|---|
[백준 11047번 C/C++] 동전 0 (1) | 2023.06.13 |
[백준 1181번 C/C++] 단어 정렬 (0) | 2023.06.10 |
[백준 11650번 C/C++] 좌표 정렬하기 (0) | 2023.06.09 |
[백준 2579번 C/C++] 계단 오르기 (0) | 2023.06.09 |
댓글
이 글 공유하기
다른 글
-
[백준 11866번 C/C++] 요세푸스 문제 0
[백준 11866번 C/C++] 요세푸스 문제 0
2023.06.14 -
[백준 11047번 C/C++] 동전 0
[백준 11047번 C/C++] 동전 0
2023.06.13 -
[백준 1181번 C/C++] 단어 정렬
[백준 1181번 C/C++] 단어 정렬
2023.06.10 -
[백준 11650번 C/C++] 좌표 정렬하기
[백준 11650번 C/C++] 좌표 정렬하기
2023.06.09