<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>스텍 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%EC%8A%A4%ED%85%8D/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 26 Nov 2025 01:26:08 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>스텍 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 4949번 (균형잡힌 세상, C++, Stack) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/4949-balanced-world-c-stack-baekjoon/4537/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/4949-balanced-world-c-stack-baekjoon/4537/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 13 Jan 2023 22:10:06 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[4949]]></category>
		<category><![CDATA[4949번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Stack]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[균형잡힌 세상]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 4949]]></category>
		<category><![CDATA[백준 4949번]]></category>
		<category><![CDATA[스텍]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[자료구조]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4537</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 4949번 '균형잡힌 세상' 문제에 대한 글입니다. 'stack' 으로 해결하였</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/4949-balanced-world-c-stack-baekjoon/4537/">백준 4949번 (균형잡힌 세상, C++, Stack) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">균형잡힌 세상</h2>



<p class="has-medium-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/problem/4949" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/4949</a></p>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">82038</td><td class="has-text-align-left" data-align="left">27279</td><td class="has-text-align-left" data-align="left">21453</td><td class="has-text-align-left" data-align="left">32.336%</td></tr></tbody></table></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">문제</h3>



<p class="has-medium-font-size wp-block-paragraph">세계는 균형이 잘 잡혀있어야 한다. </p>



<p class="has-medium-font-size wp-block-paragraph">양과 음, 빛과 어둠 그리고 왼쪽 괄호와 오른쪽 괄호처럼 말이다.</p>



<p class="has-medium-font-size wp-block-paragraph">정민이의 임무는 어떤 문자열이 주어졌을 때, </p>



<p class="has-medium-font-size wp-block-paragraph">괄호들의 균형이 잘 맞춰져 있는지 판단하는 프로그램을 짜는 것이다.</p>



<p class="has-medium-font-size wp-block-paragraph">문자열에 포함되는 괄호는 소괄호(&#8220;()&#8221;) 와 대괄호(&#8220;[]&#8221;)로 2종류이고, </p>



<p class="has-medium-font-size wp-block-paragraph">문자열이 균형을 이루는 조건은 아래와 같다.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">모든 왼쪽 소괄호(&#8220;(&#8220;)는 오른쪽 소괄호(&#8220;)&#8221;)와만 짝을 이뤄야 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">모든 왼쪽 대괄호(&#8220;[&#8220;)는 오른쪽 대괄호(&#8220;]&#8221;)와만 짝을 이뤄야 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">모든 오른쪽 괄호들은 자신과 짝을 이룰 수 있는 왼쪽 괄호가 존재한다.</p>



<p class="has-medium-font-size wp-block-paragraph">모든 괄호들의 짝은 1:1 매칭만 가능하다. 즉, 괄호 하나가 둘 이상의 괄호와 짝지어지지 않는다.</p>



<p class="has-medium-font-size wp-block-paragraph">짝을 이루는 두 괄호가 있을 때, 그 사이에 있는 문자열도 균형이 잡혀야 한다.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">정민이를 도와 문자열이 주어졌을 때 균형잡힌 문자열인지 아닌지를 판단해보자.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">입력</h3>



<p class="has-medium-font-size wp-block-paragraph">하나 또는 여러줄에 걸쳐서 문자열이 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">각 문자열은 영문 알파벳, 공백, 소괄호(&#8220;( )&#8221;) 대괄호(&#8220;[ ]&#8221;)등으로 이루어져 있으며, </p>



<p class="has-medium-font-size wp-block-paragraph">길이는 100글자보다 작거나 같다. 각 줄은 마침표(&#8220;.&#8221;)로 끝난다.</p>



<p class="has-medium-font-size wp-block-paragraph">입력의 종료조건으로 맨 마지막에 점 하나(&#8220;.&#8221;)가 들어온다.</p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">출력</h3>



<p class="has-medium-font-size wp-block-paragraph">각 줄마다 해당 문자열이 균형을 이루고 있으면 &#8220;yes&#8221;를, 아니면 &#8220;no&#8221;를 출력한다.</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">예제 입력 1</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">So when I die (the [first] I will see in (heaven) is a score list).
[ first in ] ( first out ).
Half Moon tonight (At least it is better than no Moon at all].
A rope may form )( a trail in a maze.
Help( I[m being held prisoner in a fortune cookie factory)].
([ (([( [ ] ) ( ) (( ))] )) ]).
 .
.</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">yes
yes
no
no
no
yes
yes</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">예제 입력 A</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[()][.
].
(().
x.
((((.
(]).
.</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">예제 출력 A</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">no
no
no
yes
no
no</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">예제 입력 B</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">([(([])[]))]
 .
(])
.</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">예제 출력 B</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">no
yes
no</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">예제 입력 C</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">([)].
([)]).
()[]
[()()).
[(()].
[]][.
()][.
.</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">예제 출력 C</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">no
no
yes
no
no
no
no</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">힌트</h3>



<p class="has-medium-font-size wp-block-paragraph">7번째의 &#8221; .&#8221;와 같이 괄호가 하나도 없는 경우도 균형잡힌 문자열로 간주할 수 있다.</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">출처</h3>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">ICPC</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/42" target="_blank" rel="noreferrer noopener">Asia Pacific</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/43" target="_blank" rel="noreferrer noopener">Japan</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/44" target="_blank" rel="noreferrer noopener">Japan Domestic Contest</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/201">2011 J</a><a href="https://www.acmicpc.net/category/detail/201" target="_blank" rel="noreferrer noopener">a</a><a href="https://www.acmicpc.net/category/detail/201">pan Domestic Contest</a>&nbsp;B번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/chminoo" target="_blank" rel="noreferrer noopener">chminoo</a></li>



<li>잘못된 번역을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>



<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/occidere" target="_blank" rel="noreferrer noopener">occidere</a></li>
</ul>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/158" target="_blank" rel="noreferrer noopener">문자열</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/71" target="_blank" rel="noreferrer noopener">스택</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size wp-block-paragraph">문자열로 입력을 받아서 인덱스 0 부터 문자열을 순회한다.</p>



<p class="has-medium-font-size wp-block-paragraph">만약 ( [ 이 나온다면 stack에 넣고,</p>



<p class="has-medium-font-size wp-block-paragraph"> ) ] 이 나온다면 stack의 top 문자와 비교하여 균형이 잡혀있는지 판별해준다. </p>



<p class="has-medium-font-size wp-block-paragraph">중간에 예외 처리도 잊으면 안된다. ( ex. 문자가 ) ] 이지만 stack이 비어있는 경우)</p>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">통과된 코드</h3>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;stack>
#include &lt;list>
#include &lt;string>

using namespace std;

stack&lt;char> myStack;
list&lt;string> myList;
string str;
bool check = true;

int main()
{
	while (true)
	{
		getline(cin, str);
		if (str == ".") break; // 초기화
		check = true; // 초기화

		for (int i = 0; i &lt; str.length(); i++) {
			if (str[i] == '(' || str[i] == '[') myStack.push(str[i]);
			else if (str[i] == ')' || str[i] == ']') {
				if (myStack.empty()) {  // stack이 비어 있는데 ) ] 가 나올 수 없다.
					check = false; // 균형을 이루지 않음
					break;
				}

				if (str[i] == ')' &amp;&amp; myStack.top() == '(') myStack.pop();
				else if (str[i] == ']' &amp;&amp; myStack.top() == '[') myStack.pop();
				else check = false;  // 균형을 이루지 않음
			}
		}

		if (myStack.empty() &amp;&amp; check) myList.push_back("yes");
		else myList.push_back("no");

		while (!myStack.empty()) myStack.pop(); // stack 초기화

	}

	// 판별한 결과를 출력합니다.
	for (auto it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; "\n";

	return 0;
}</pre>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1034" height="273" src="https://lycos7560.com/wp-content/uploads/image-937.png" alt="" class="wp-image-4540" srcset="https://lycos7560.com/wp-content/uploads/image-937.png 1034w, https://lycos7560.com/wp-content/uploads/image-937-300x79.png 300w, https://lycos7560.com/wp-content/uploads/image-937-768x203.png 768w" sizes="(max-width: 1034px) 100vw, 1034px" /></figure>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">뭐가 잘못된지 몰라서 이것 저것 시도해보다가 나락 간 문제</p>



<div style="height:48px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/4949-balanced-world-c-stack-baekjoon/4537/">백준 4949번 (균형잡힌 세상, C++, Stack) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/4949-balanced-world-c-stack-baekjoon/4537/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 10773번 (제로, C++, stack) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/10773-zero-c-stack-baekjoon/4495/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/10773-zero-c-stack-baekjoon/4495/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 13 Jan 2023 10:47:02 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[10773]]></category>
		<category><![CDATA[10773번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[Stack]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 10773]]></category>
		<category><![CDATA[백준 10773번]]></category>
		<category><![CDATA[스텍]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[자료구조]]></category>
		<category><![CDATA[제로]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4495</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 10773번 '제로' 문제에 대한 글입니다.  'stack'을 이용하여 해결하였습니다. (This is BAEKJOON's 10773 'Zero' question. Resolved using 'stack'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/10773-zero-c-stack-baekjoon/4495/">백준 10773번 (제로, C++, stack) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:68px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">제로</h1>



<p class="has-medium-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/problem/10773" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/10773</a></p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">59548</td><td class="has-text-align-left" data-align="left">39867</td><td class="has-text-align-left" data-align="left">32905</td><td class="has-text-align-left" data-align="left">67.416%</td></tr></tbody></table></figure>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size wp-block-paragraph">나코더 기장 재민이는 동아리 회식을 준비하기 위해서 장부를 관리하는 중이다.</p>



<p class="has-medium-font-size wp-block-paragraph">재현이는 재민이를 도와서 돈을 관리하는 중인데, </p>



<p class="has-medium-font-size wp-block-paragraph">애석하게도 항상 정신없는 재현이는 돈을 실수로 잘못 부르는 사고를 치기 일쑤였다.</p>



<p class="has-medium-font-size wp-block-paragraph">재현이는 잘못된 수를 부를 때마다 0을 외쳐서, 가장 최근에 재민이가 쓴 수를 지우게 시킨다.</p>



<p class="has-medium-font-size wp-block-paragraph">재민이는 이렇게 모든 수를 받아 적은 후 그 수의 합을 알고 싶어 한다. </p>



<p class="has-medium-font-size wp-block-paragraph">재민이를 도와주자!</p>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size wp-block-paragraph">첫 번째 줄에 정수 K가 주어진다. (1 ≤ K ≤ 100,000)</p>



<p class="has-medium-font-size wp-block-paragraph">이후 K개의 줄에 정수가 1개씩 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">정수는 0에서 1,000,000 사이의 값을 가지며, </p>



<p class="has-medium-font-size wp-block-paragraph">정수가 &#8220;0&#8221; 일 경우에는 가장 최근에 쓴 수를 지우고, 아닐 경우 해당 수를 쓴다.</p>



<p class="has-medium-font-size wp-block-paragraph">정수가 &#8220;0&#8221;일 경우에 지울 수 있는 수가 있음을 보장할 수 있다.</p>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size wp-block-paragraph">재민이가 최종적으로 적어 낸 수의 합을 출력한다. </p>



<p class="has-medium-font-size wp-block-paragraph">최종적으로 적어낸 수의 합은 2<sup>31</sup>-1보다 작거나 같은 정수이다.</p>



<div style="height:48px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4
3
0
4
0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10
1
3
5
4
0
0
7
0
0
6</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">7</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">힌트</h2>



<p class="has-medium-font-size wp-block-paragraph">예제 2의 경우를 시뮬레이션 해보면,</p>



<ul class="wp-block-list">
<li>[1]</li>



<li>[1,3]</li>



<li>[1,3,5]</li>



<li>[1,3,5,4]</li>



<li>[1,3,5] (0을 불렀기 때문에 최근의 수를 지운다)</li>



<li>[1,3] (0을 불렀기 때문에 그 다음 최근의 수를 지운다)</li>



<li>[1,3,7]</li>



<li>[1,3] (0을 불렀기 때문에 최근의 수를 지운다)</li>



<li>[1] (0을 불렀기 때문에 그 다음 최근의 수를 지운다)</li>



<li>[1,6]</li>
</ul>



<p class="has-medium-font-size wp-block-paragraph">합은 7이다.</p>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/173" target="_blank" rel="noreferrer noopener">Canadian Computing Competition &amp; Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/315" target="_blank" rel="noreferrer noopener">2015</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/1345" target="_blank" rel="noreferrer noopener">CCC 2015 Senior Division</a>&nbsp;1번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/busyhuman" target="_blank" rel="noreferrer noopener">busyhuman</a></li>



<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/koosaga" target="_blank" rel="noreferrer noopener">koosaga</a></li>
</ul>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102">구</a><a href="https://www.acmicpc.net/problem/tag/102" target="_blank" rel="noreferrer noopener">현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/71" target="_blank" rel="noreferrer noopener">스택</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size wp-block-paragraph">스텍(Stack)의 자료 구조를 알고 있다면 쉽게 해결 할 수 있는 문제</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="919" height="428" src="https://lycos7560.com/wp-content/uploads/image-929.png" alt="" class="wp-image-4498" srcset="https://lycos7560.com/wp-content/uploads/image-929.png 919w, https://lycos7560.com/wp-content/uploads/image-929-300x140.png 300w, https://lycos7560.com/wp-content/uploads/image-929-768x358.png 768w" sizes="(max-width: 919px) 100vw, 919px" /></figure>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;stack>

using namespace std;

stack&lt;int> myStack;

int N, temp;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N;
	
	while (N-- > 0) {
		cin >> temp;
		// 입력이 0보다 클 경우 push
		// 작을 경우 pop
		if (temp > 0) myStack.push(temp);
		else myStack.pop();
	}

	temp = 0;

	// stack 내부의 값을 전부 더 해준다.
	while (!myStack.empty()) {
		temp += myStack.top();
		myStack.pop();
	}

	cout &lt;&lt; temp;

	return 0;
}</pre>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="909" height="124" src="https://lycos7560.com/wp-content/uploads/image-928.png" alt="" class="wp-image-4496" srcset="https://lycos7560.com/wp-content/uploads/image-928.png 909w, https://lycos7560.com/wp-content/uploads/image-928-300x41.png 300w, https://lycos7560.com/wp-content/uploads/image-928-768x105.png 768w" sizes="(max-width: 909px) 100vw, 909px" /></figure>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/10773-zero-c-stack-baekjoon/4495/">백준 10773번 (제로, C++, stack) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/10773-zero-c-stack-baekjoon/4495/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1874번 (스택 수열, C++, stack) [BAEKJOON] / 추가 반례</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/1874-stack-sequence-c-stack-baekjoon/4488/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/1874-stack-sequence-c-stack-baekjoon/4488/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 13 Jan 2023 10:25:44 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1874]]></category>
		<category><![CDATA[1874번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Stack]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1874]]></category>
		<category><![CDATA[백준 1874번]]></category>
		<category><![CDATA[스택 수열]]></category>
		<category><![CDATA[스택수열]]></category>
		<category><![CDATA[스텍]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4488</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1874번 '스택 수열' 문제에 대한 글입니다. (This is an article about the 'stack sequence' problem in BAEKJOON 1874.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1874-stack-sequence-c-stack-baekjoon/4488/">백준 1874번 (스택 수열, C++, stack) [BAEKJOON] / 추가 반례</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:68px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">스택 수열</h1>



<p class="has-medium-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/problem/1874" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1874</a></p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">109378</td><td class="has-text-align-left" data-align="left">41343</td><td class="has-text-align-left" data-align="left">29203</td><td class="has-text-align-left" data-align="left">36.898%</td></tr></tbody></table></figure>



<div style="height:59px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size wp-block-paragraph">스택 (stack)은 기본적인 자료구조 중 하나로, 컴퓨터 프로그램을 작성할 때 자주 이용되는 개념이다. </p>



<p class="has-medium-font-size wp-block-paragraph">스택은 자료를 넣는 (push) 입구와 자료를 뽑는 (pop) 입구가 같아 제일 나중에 들어간 자료가 </p>



<p class="has-medium-font-size wp-block-paragraph">제일 먼저 나오는 (LIFO, Last in First out) 특성을 가지고 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">1부터 n까지의 수를 스택에 넣었다가 뽑아 늘어놓음으로써, 하나의 수열을 만들 수 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">이때, 스택에 push하는 순서는 반드시 오름차순을 지키도록 한다고 하자. </p>



<p class="has-medium-font-size wp-block-paragraph">임의의 수열이 주어졌을 때 스택을 이용해 그 수열을 만들 수 있는지 없는지, </p>



<p class="has-medium-font-size wp-block-paragraph">있다면 어떤 순서로 push와 pop 연산을 수행해야 하는지를 알아낼 수 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">이를 계산하는 프로그램을 작성하라.</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size wp-block-paragraph">첫 줄에 n (1 ≤ n ≤ 100,000)이 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">둘째 줄부터 n개의 줄에는 수열을 이루는 1이상 n이하의 정수가 하나씩 순서대로 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">물론 같은 정수가 두 번 나오는 일은 없다.</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size wp-block-paragraph">입력된 수열을 만들기 위해 필요한 연산을 한 줄에 한 개씩 출력한다. </p>



<p class="has-medium-font-size wp-block-paragraph">push연산은 +로, pop 연산은 -로 표현하도록 한다. </p>



<p class="has-medium-font-size wp-block-paragraph">불가능한 경우 NO를 출력한다.</p>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8
4
3
6
8
7
5
2
1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">+
+
+
+
-
-
+
+
-
+
+
-
-
-
-
-</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
1
2
5
3
4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">NO</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">20
4
5 
6 
10 
9 
8 
7 
11 
12 
13 
3 
2 
1 
16
15 
20 
19 
18 
17 
14</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">+
+
+
+
-
+
-
+
-
+
+
+
+
-
-
-
-
+
-
+
-
+
-
-
-
-
+
+
+
-
-
+
+
+
+
-
-
-
-
-</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">20
4
5
6
10
9
8
7
11
12
14
13
3
2
1
15
16
20
19
18
17</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">+
+
+
+
-
+
-
+
-
+
+
+
+
-
-
-
-
+
-
+
-
+
+
-
-
-
-
-
+
-
+
-
+
+
+
+
-
-
-
-</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8
2
4
7
5
3
1
8
6</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">NO</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1
1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">+
-</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6
2
3
4
5
6
1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">+
+
-
+
-
+
-
+
-
+
-
-</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">힌트</h2>



<p class="has-medium-font-size wp-block-paragraph">1부터 n까지에 수에 대해 차례로 </p>



<p class="has-medium-font-size wp-block-paragraph">[push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] </p>



<p class="has-medium-font-size wp-block-paragraph">연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다.</p>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/author5" target="_blank" rel="noreferrer noopener">author5</a></li>



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/bgjuw12" target="_blank" rel="noreferrer noopener">bgjuw12</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a>,&nbsp;<a href="https://www.acmicpc.net/user/scala0114" target="_blank" rel="noreferrer noopener">scala0114</a></li>
</ul>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/71" target="_blank" rel="noreferrer noopener">스택</a></li>
</ul>



<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="431" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230113_192314175.jpg" alt="" class="wp-image-4493" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230113_192314175.jpg 1600w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230113_192314175-300x81.jpg 300w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230113_192314175-768x207.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230113_192314175-1536x414.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



<div style="height:49px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;list>
#include &lt;stack>

using namespace std;

list&lt;int> myList;
list&lt;char> resultList;
stack&lt;int> myStack;

int N, temp;
bool check = true;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N;

	for (int i = 0; i &lt; N; i++) {
		cin >> temp;
		myList.push_back(temp);
	}

	temp = 1;

	for (auto it = myList.begin(); it != myList.end(); it++) {
		
		if (*it >= temp) {
			for (int i = temp; i &lt;= *it; i++) {
				myStack.push(temp);
				resultList.push_back('+');
				temp++;
			}
		}

		if (!myStack.empty() &amp;&amp; myStack.top() == *it) {
			myStack.pop();
			resultList.push_back('-');
		}
		else {
			check = false;
			break;
		}
	}

	if (check) {
		for (auto it = resultList.begin(); it != resultList.end(); it++) {
			cout &lt;&lt; *it &lt;&lt; "\n";
		}
	}
	else {
		cout &lt;&lt; "NO";
	}

	return 0;
}</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="909" height="209" src="https://lycos7560.com/wp-content/uploads/image-927.png" alt="" class="wp-image-4489" srcset="https://lycos7560.com/wp-content/uploads/image-927.png 909w, https://lycos7560.com/wp-content/uploads/image-927-300x69.png 300w, https://lycos7560.com/wp-content/uploads/image-927-768x177.png 768w" sizes="(max-width: 909px) 100vw, 909px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">문제 이해를 제대로 못해서 틀린 문제</p>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1874-stack-sequence-c-stack-baekjoon/4488/">백준 1874번 (스택 수열, C++, stack) [BAEKJOON] / 추가 반례</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/1874-stack-sequence-c-stack-baekjoon/4488/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
