Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- TCP/IP
- FIFO paging
- Spring
- 김영한
- 10026번
- inflearn
- 토마토
- Operating System
- 스프링 입문
- 열혈 TCP/IP 소켓 프로그래밍
- n타일링2
- 2475번
- redis
- 열혈 tcp/ip 프로그래밍
- 스프링 핵심 원리
- 운영체제
- 이펙티브코틀린
- Window-Via-c/c++
- BOJ
- Four Squares
- C#
- 윤성우 저자
- HTTP
- 우아한레디스
- 에러핸들링
- C++
- 제프리리처
- 우아한 테크 세미나
- OS
- Operating System.
Archives
- Today
- Total
나의 브을로오그으
[c++] 1874번 : 스택 수열 본문
#include <iostream>
#include <stack>
#include <list>
using namespace std;
bool isMakeNumOfASC(list<char>* outputList, stack<int>* stack, int seq)
{
while (stack->empty() == false)
{
if (stack->top() == seq)
{
stack->pop();
outputList->push_back('-');
return true;
}
stack->pop();
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
stack<int> stack;
list<char> outputList;
int n = 0;
int num = 1;
int seq = 0;
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> seq;
while (num <= seq)
{
stack.push(num);
outputList.push_back('+');
++num;
}
if (stack.empty() == true || isMakeNumOfASC(&outputList, &stack, seq) == false)
{
cout << "NO" << "\n";
return 0;
}
}
list<char>::iterator iter;
list<char>::iterator iterEnd = outputList.end();
for (iter = outputList.begin(); iter != iterEnd; ++iter)
{
cout << *iter << "\n";
}
return 0;
}
https://www.acmicpc.net/problem/1874
1874번: 스택 수열
1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다.
www.acmicpc.net
'알고리즘 > BaekJoon' 카테고리의 다른 글
[c++] 1929번 : 소수 구하기 (0) | 2022.03.28 |
---|---|
[c++] 1920번 : 수 찾기 (0) | 2022.03.25 |
[c++] 1654번 : 랜선 자르기 (0) | 2022.03.23 |
[c++] 1436번 : 영화감독 숌 (0) | 2022.03.22 |
[c++] 1259번 : 팰린드롬 수 (0) | 2022.03.22 |