<?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>sort Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/sort/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 15 Oct 2025 05:34:39 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>sort Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Ubuntu – 파이프(Pipe)/필터(filter)/리다이렉션(redirection)</title>
		<link>https://lycos7560.com/ubuntu/ubuntu-%ed%8c%8c%ec%9d%b4%ed%94%84pipe-%ed%95%84%ed%84%b0filter-%eb%a6%ac%eb%8b%a4%ec%9d%b4%eb%a0%89%ec%85%98redirection/38877/</link>
					<comments>https://lycos7560.com/ubuntu/ubuntu-%ed%8c%8c%ec%9d%b4%ed%94%84pipe-%ed%95%84%ed%84%b0filter-%eb%a6%ac%eb%8b%a4%ec%9d%b4%eb%a0%89%ec%85%98redirection/38877/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 02 Dec 2024 10:23:17 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[command chaining]]></category>
		<category><![CDATA[command filtering]]></category>
		<category><![CDATA[cut]]></category>
		<category><![CDATA[data processing]]></category>
		<category><![CDATA[data sorting]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[error redirection]]></category>
		<category><![CDATA[file input]]></category>
		<category><![CDATA[file saving]]></category>
		<category><![CDATA[file sorting]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filter commands]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[input redirection]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux basic commands]]></category>
		<category><![CDATA[Linux shell]]></category>
		<category><![CDATA[Linux shell commands]]></category>
		<category><![CDATA[Log Analysis]]></category>
		<category><![CDATA[log file]]></category>
		<category><![CDATA[log filtering]]></category>
		<category><![CDATA[output file]]></category>
		<category><![CDATA[output redirection]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[pipe usage]]></category>
		<category><![CDATA[pipeline]]></category>
		<category><![CDATA[pipeline usage]]></category>
		<category><![CDATA[Process Management]]></category>
		<category><![CDATA[real-time monitoring]]></category>
		<category><![CDATA[redirection]]></category>
		<category><![CDATA[redirection examples]]></category>
		<category><![CDATA[redirection usage]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell commands]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[standard error]]></category>
		<category><![CDATA[standard output]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[system automation]]></category>
		<category><![CDATA[System Monitoring]]></category>
		<category><![CDATA[system tuning]]></category>
		<category><![CDATA[tail]]></category>
		<category><![CDATA[text filtering]]></category>
		<category><![CDATA[text processing]]></category>
		<category><![CDATA[text transformation]]></category>
		<category><![CDATA[wc]]></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>
		<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>
		<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>
		<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>
		<category><![CDATA[필터 명령어]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=38877</guid>

					<description><![CDATA[<p>파이프(Pipe) 파이프(&#124;)는 하나의 명령어 출력을 다른 명령어의 입력으로 전달하는 역할 파이프는 명령어의 출력을 다른 명령어로 전달하는데 매우 유용하며, 이로 인해 복잡한 작업을 단순화할 수 있음 사용법 필터(Filter) 필터는 파이프와 함께 사용되며, 데이터를 수정하거나 변환하는 명령어 보통 출력된 데이터를 필터링하거나 변경할 때 사용 grep, awk, sed, sort, cut, tail, wc 등의 명령어가 필터에 해당 사용법 리디렉션(Redirection) 리디렉션은 명령어의 출력을 파일로 저장하거나, [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/ubuntu/ubuntu-%ed%8c%8c%ec%9d%b4%ed%94%84pipe-%ed%95%84%ed%84%b0filter-%eb%a6%ac%eb%8b%a4%ec%9d%b4%eb%a0%89%ec%85%98redirection/38877/">Ubuntu – 파이프(Pipe)/필터(filter)/리다이렉션(redirection)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-05896234      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#파이프pipe" class="uagb-toc-link__trigger">파이프(Pipe)</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#사용법" class="uagb-toc-link__trigger">사용법</a></li></ul></li><li class="uagb-toc__list"><a href="#필터filter" class="uagb-toc-link__trigger">필터(Filter)</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#사용법" class="uagb-toc-link__trigger">사용법</a></li></ul></li></ul></li><li class="uagb-toc__list"><a href="#리디렉션redirection" class="uagb-toc-link__trigger">리디렉션(Redirection)</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#출력-리디렉션" class="uagb-toc-link__trigger">출력 리디렉션</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#입력-리디렉션" class="uagb-toc-link__trigger">입력 리디렉션</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#표준-오류-리디렉션" class="uagb-toc-link__trigger">표준 오류 리디렉션</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#출력과-오류-모두-리디렉션" class="uagb-toc-link__trigger">출력과 오류 모두 리디렉션</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#파이프-필터-리디렉션을-결합-예시" class="uagb-toc-link__trigger">파이프, 필터, 리디렉션을 결합 예시</a></ul></ul></ul></ol>					</div>
									</div>
				</div>
			


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



<h3 class="wp-block-heading"><strong>파이프(Pipe)</strong></h3>



<p>파이프(<code>|</code>)는 하나의 명령어 출력을 다른 명령어의 입력으로 전달하는 역할</p>



<p>파이프는 명령어의 출력을 다른 명령어로 전달하는데 매우 유용하며, 이로 인해 복잡한 작업을 단순화할 수 있음</p>



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



<h4 class="wp-block-heading"><strong>사용법</strong></h4>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# command1은 먼저 실행되어 출력을 생성하고, 이 출력이 command2로 전달
command1 | command2
</pre>



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



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# ls 명령어로 디렉토리 목록을 출력하고, 그 결과를 less 명령어로 페이지 단위로 스크롤할 수 있게 만듬
ls -al | less
ls -al /etc | less</pre>



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



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# ps aux로 실행 중인 프로세스를 나열하고, 그 중에서 apache라는 단어가 포함된 항목만 필터링하여 출력
ps aux | grep apache
</pre>



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



<h3 class="wp-block-heading"><strong><strong>필터(Filter)</strong></strong></h3>



<p>필터는 파이프와 함께 사용되며, 데이터를 수정하거나 변환하는 명령어</p>



<p>보통 출력된 데이터를 필터링하거나 변경할 때 사용</p>



<p><code>grep</code>, <code>awk</code>, <code>sed</code>, <code>sort</code>, <code>cut, tail, wc</code> 등의 명령어가 필터에 해당</p>



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



<h4 class="wp-block-heading">사용법</h4>



<ul class="wp-block-list">
<li><strong><code>grep</code></strong>: 패턴에 맞는 줄을 검색</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# file.txt에서 keyword를 포함하는 줄만 출력
cat file.txt | grep "keyword"

# ps -ef는 모든 프로세스 번호를 출력하므로 bash 라는 글자가 들어간 프로세스만 출력
ps -ef | grep bash</pre>



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



<ul class="wp-block-list">
<li><strong><code>awk</code></strong>: 파일을 특정 구분자로 나누어 처리</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# file.txt의 각 줄에서 첫 번째 열만 출력
cat file.txt | awk '{print $1}'
</pre>



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



<ul class="wp-block-list">
<li><strong><code>sort</code></strong>: 데이터를 정렬</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# 디렉토리 내 파일들을 알파벳 순으로 정렬하여 출력
ls | sort
</pre>



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



<ul class="wp-block-list">
<li><strong><code>cut</code></strong>: 텍스트를 구분자로 나누어 일부만 선택.</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# file.txt에서 공백을 기준으로 첫 번째 필드를 출력
cat file.txt | cut -d' ' -f1

</pre>



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



<ul class="wp-block-list">
<li><strong><code>sed</code></strong>: 텍스트 스트림을 수정(편집).</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# file.txt에서 old라는 단어를 new로 바꿔 출력
cat file.txt | sed 's/old/new/g'

</pre>



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



<h3 class="wp-block-heading"><strong><strong><strong>리디렉션(Redirection)</strong></strong></strong></h3>



<p>리디렉션은 명령어의 출력을 파일로 저장하거나, 파일을 명령어의 입력으로 전달하는 기능</p>



<p>리디렉션은 <strong>출력 리디렉션</strong>과 <strong>입력 리디렉션</strong>으로 나눌 수 있음</p>



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



<h4 class="wp-block-heading"><strong>출력 리디렉션</strong></h4>



<p>출력 리디렉션은 명령어의 출력을 파일로 보낼 때 사용 <code>></code> 또는 <code>>></code>를 사용</p>



<ul class="wp-block-list">
<li><strong><code>></code></strong> 출력을 새로운 파일에 덮어쓰기</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# "Hello, World!"를 hello.txt라는 파일에 덮어씁니다.
echo "Hello, World!" > hello.txt
</pre>



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



<ul class="wp-block-list">
<li><strong><code>>></code></strong> 출력을 파일 끝에 추가</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# "New line"을 hello.txt 파일에 추가합니다.
echo "New line" >> hello.txt
</pre>



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



<h4 class="wp-block-heading"><strong><strong>입력 리디렉션</strong></strong></h4>



<p>입력 리디렉션은 파일을 명령어의 입력으로 전달하는 데 사용 <code>&lt;</code> 기호를 사용</p>



<ul class="wp-block-list">
<li><strong><code>&lt;</code></strong>: 파일을 명령어의 입력으로 사용</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# file.txt의 내용을 정렬하여 출력
sort &lt; file.txt

# list.txt 파일을 정렬하고 out.txt에 쓰기
sort &lt; list.txt > out.txt
</pre>



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



<h4 class="wp-block-heading"><strong><strong><strong>표준 오류 리디렉션</strong></strong></strong></h4>



<p>표준 오류를 파일로 리디렉션할 수 있습니다. <code>2></code> 또는 <code>2>></code>를 사용</p>



<ul class="wp-block-list">
<li><strong><code>2></code></strong>: 오류 출력을 파일로 리디렉션</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# 명령어의 오류 메시지를 error.log 파일에 저장
command 2> error.log
</pre>



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



<ul class="wp-block-list">
<li><strong><code>2>></code></strong>: 오류 출력을 파일 끝에 추가</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># 명령어의 오류 메시지를 error.log 파일 끝에 저장
command 2>> error.log

</pre>



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



<h4 class="wp-block-heading"><strong><strong><strong><strong>출력과 오류 모두 리디렉션</strong></strong></strong></strong></h4>



<p>출력과 오류를 모두 하나의 파일로 리디렉션</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># output.log 파일에 표준 출력과 표준 오류가 모두 기록
command > output.log 2>&amp;1
</pre>



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



<h4 class="wp-block-heading"><strong><strong><strong><strong><strong>파이프, 필터, 리디렉션을 결합 예시</strong></strong></strong></strong></strong></h4>



<p>여러 명령어를 조합하여 복잡한 작업을 할 수 있습니다.</p>



<p>예를 들어, 특정 로그 파일에서 오류 메시지만 추출하여 정렬하고, 이를 파일로 저장할 수 있습니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
# /var/log/syslog 파일에서 "error"라는 단어가 포함된 행을 찾고, 그 결과를 정렬하여 error_log.txt에 저장합니다.
cat /var/log/syslog | grep "error" | sort > error_log.txt

</pre>



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



<p></p>
<p>The post <a href="https://lycos7560.com/ubuntu/ubuntu-%ed%8c%8c%ec%9d%b4%ed%94%84pipe-%ed%95%84%ed%84%b0filter-%eb%a6%ac%eb%8b%a4%ec%9d%b4%eb%a0%89%ec%85%98redirection/38877/">Ubuntu – 파이프(Pipe)/필터(filter)/리다이렉션(redirection)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/ubuntu/ubuntu-%ed%8c%8c%ec%9d%b4%ed%94%84pipe-%ed%95%84%ed%84%b0filter-%eb%a6%ac%eb%8b%a4%ec%9d%b4%eb%a0%89%ec%85%98redirection/38877/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2587번 (대표값2, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2587%eb%b2%88-%eb%8c%80%ed%91%9c%ea%b0%922-c-baekjoon/35752/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2587%eb%b2%88-%eb%8c%80%ed%91%9c%ea%b0%922-c-baekjoon/35752/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 07 Jul 2023 21:13:56 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2587]]></category>
		<category><![CDATA[2587번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[대표값2]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2587]]></category>
		<category><![CDATA[백준 2587번]]></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=35752</guid>

					<description><![CDATA[<p>백준 2587번 '대표값2' 문제에 대한글입니다.  (This is an article about Baekjoon Number 2587 'Representative Value 2'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2587%eb%b2%88-%eb%8c%80%ed%91%9c%ea%b0%922-c-baekjoon/35752/">백준 2587번 (대표값2, C++) [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>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-8b0bfb40      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#대표값2" class="uagb-toc-link__trigger">대표값2</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">대표값2</h1>



<p><a href="https://www.acmicpc.net/problem/2587" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/2587</a></p>



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



<figure class="wp-block-table"><table><thead><tr><th>시간 제한</th><th>메모리 제한</th><th>제출</th><th>정답</th><th>맞힌 사람</th><th>정답 비율</th></tr></thead><tbody><tr><td>1 초</td><td>128 MB</td><td>31241</td><td>19249</td><td>17720</td><td>62.379%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>어떤 수들이 있을 때, 그 수들을 대표하는 값으로 가장 흔하게 쓰이는 것은 평균이다. </p>



<p>평균은 주어진 모든 수의 합을 수의 개수로 나눈 것이다. </p>



<p>예를 들어 10, 40, 30, 60, 30의 평균은 (10 + 40 + 30 + 60 + 30) / 5 = 170 / 5 = 34가 된다.</p>



<p>평균 이외의 또 다른 대표값으로 중앙값이라는 것이 있다. </p>



<p>중앙값은 주어진 수를 크기 순서대로 늘어 놓았을 때 가장 중앙에 놓인 값이다. </p>



<p>예를 들어 10, 40, 30, 60, 30의 경우, 크기 순서대로 늘어 놓으면</p>



<p>10 30 30 40 60</p>



<p>이 되고 따라서 중앙값은 30이 된다.</p>



<p>다섯 개의 자연수가 주어질 때 이들의 평균과 중앙값을 구하는 프로그램을 작성하시오.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄부터 다섯 번째 줄까지 한 줄에 하나씩 자연수가 주어진다. </p>



<p>주어지는 자연수는 100 보다 작은 10의 배수이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>첫째 줄에는 평균을 출력하고, 둘째 줄에는 중앙값을 출력한다. </p>



<p>평균과 중앙값은 모두 자연수이다.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10
40
30
60
30</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



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



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p><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/55" target="_blank" rel="noreferrer noopener">한국정보올림피아드</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/57" target="_blank" rel="noreferrer noopener">한국정보올림피아드시․도지역본선</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/72" target="_blank" rel="noreferrer noopener">지역본선 2005</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/373" target="_blank" rel="noreferrer noopener">초등부</a>&nbsp;1번</p>



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/97">정렬</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/121" 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)"/>



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



<div style="height:20px" 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>

using namespace std;

int _Arr[6], _Sum;

int main()
{
	for (int i = 0; i &lt; 5; i++)
		cin >> _Arr[i];
	// 배열의 크기가 작아서 선택 정렬을 사용
	for (int i = 0; i &lt; 5; i++)
		for (int j = 0; j &lt; 5; j++) {
			if (i == j) continue;
			if (_Arr[i] > _Arr[j]) {
				_Arr[5] = _Arr[i];
				_Arr[i] = _Arr[j];
				_Arr[j] = _Arr[5];
			}
		}
	for (int i = 0; i &lt; 5; i++)
		_Sum += _Arr[i];
	cout &lt;&lt; (int)(_Sum / 5) &lt;&lt; "\n";
	cout &lt;&lt; _Arr[2];

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1205" height="99" src="https://lycos7560.com/wp-content/uploads/2023/07/image-15.png" alt="" class="wp-image-35755" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-15.png 1205w, https://lycos7560.com/wp-content/uploads/2023/07/image-15-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-15-768x63.png 768w" sizes="(max-width: 1205px) 100vw, 1205px" /></figure>



<div style="height:100px" 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/%eb%b0%b1%ec%a4%80-2587%eb%b2%88-%eb%8c%80%ed%91%9c%ea%b0%922-c-baekjoon/35752/">백준 2587번 (대표값2, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2587%eb%b2%88-%eb%8c%80%ed%91%9c%ea%b0%922-c-baekjoon/35752/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 10867번 (중복 빼고 정렬하기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10867%eb%b2%88-%ec%a4%91%eb%b3%b5-%eb%b9%bc%ea%b3%a0-%ec%a0%95%eb%a0%ac%ed%95%98%ea%b8%b0-c-baekjoon/35722/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10867%eb%b2%88-%ec%a4%91%eb%b3%b5-%eb%b9%bc%ea%b3%a0-%ec%a0%95%eb%a0%ac%ed%95%98%ea%b8%b0-c-baekjoon/35722/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 06 Jul 2023 05:32:30 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[10867]]></category>
		<category><![CDATA[10867번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 10867]]></category>
		<category><![CDATA[백준 10867번]]></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=35722</guid>

					<description><![CDATA[<p>백준 10867번 '중복 빼고 정렬하기' 문제에 대한 글입니다. 카운팅 정렬을 이용하여 해결하였습니다. (This article is about Baekjoon Number 10867 "Sorting Without Duplicate" problem. It was solved using counting alignment.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10867%eb%b2%88-%ec%a4%91%eb%b3%b5-%eb%b9%bc%ea%b3%a0-%ec%a0%95%eb%a0%ac%ed%95%98%ea%b8%b0-c-baekjoon/35722/">백준 10867번 (중복 빼고 정렬하기, C++) [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>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-c3a91233      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#중복-빼고-정렬하기" class="uagb-toc-link__trigger">중복 빼고 정렬하기</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">중복 빼고 정렬하기</h1>



<p><a href="https://www.acmicpc.net/problem/10867" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/10867</a></p>



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



<figure 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">17763</td><td class="has-text-align-left" data-align="left">10164</td><td class="has-text-align-left" data-align="left">8622</td><td class="has-text-align-left" data-align="left">57.381%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>N개의 정수가 주어진다. </p>



<p>이때, N개의 정수를 오름차순으로 정렬하는 프로그램을 작성하시오. </p>



<p>같은 정수는 한 번만 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄에 수의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. </p>



<p>둘째에는 숫자가 주어진다. </p>



<p>이 수는 절댓값이 1,000보다 작거나 같은 정수이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>첫째 줄에 수를 오름차순으로 정렬한 결과를 출력한다. </p>



<p>이때, 같은 수는 한 번만 출력한다.</p>



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



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



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



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



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



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



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



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



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



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



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



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/97">정렬</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)"/>



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



<p>음수가 나올 수 있다.</p>



<div style="height:20px" 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>
using namespace std;
int _N;
bool _Arr[1001][2]; // 카운팅 정렬(Counting Sort, 계수 정렬)
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N;
	int _temp;
	for (int i = 0; i &lt; _N; i++) {
		cin >> _temp;
		if (_temp &lt; 0) _Arr[-_temp][1] = true;
		else _Arr[_temp][0] = true;
	}
	for (int i = 1000; i > 0; i--)
		if (_Arr[i][1])
			cout &lt;&lt; -i &lt;&lt; " ";
	for (int i = 0; i &lt;= 1000; i++)
		if (_Arr[i][0])
			cout &lt;&lt; i &lt;&lt; " ";
	return 0;
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1202" height="97" src="https://lycos7560.com/wp-content/uploads/2023/07/image-13.png" alt="" class="wp-image-35730" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-13.png 1202w, https://lycos7560.com/wp-content/uploads/2023/07/image-13-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-13-768x62.png 768w" sizes="(max-width: 1202px) 100vw, 1202px" /></figure>



<div style="height:100px" 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/%eb%b0%b1%ec%a4%80-10867%eb%b2%88-%ec%a4%91%eb%b3%b5-%eb%b9%bc%ea%b3%a0-%ec%a0%95%eb%a0%ac%ed%95%98%ea%b8%b0-c-baekjoon/35722/">백준 10867번 (중복 빼고 정렬하기, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10867%eb%b2%88-%ec%a4%91%eb%b3%b5-%eb%b9%bc%ea%b3%a0-%ec%a0%95%eb%a0%ac%ed%95%98%ea%b8%b0-c-baekjoon/35722/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 10815번 (숫자 카드, C++, Binary Search) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 31 Jan 2023 13:12:25 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[10815]]></category>
		<category><![CDATA[10815번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Binary Search]]></category>
		<category><![CDATA[BinarySearch]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 10815]]></category>
		<category><![CDATA[백준 10815번]]></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=5862</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 10815번 '숫자 카드' 문제에 대한 글입니다. 'Binary Search' 를 이용하여 해결하였습니다. (This is an article about the 'number card' problem in BAEKJOON 10815. I solved it using 'Binary Search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/">백준 10815번 (숫자 카드, C++, Binary Search) [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>



<h1 class="wp-block-heading">숫자 카드</h1>



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



<div style="height:40px" 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">256 MB</td><td class="has-text-align-left" data-align="left">70735</td><td class="has-text-align-left" data-align="left">32252</td><td class="has-text-align-left" data-align="left">23137</td><td class="has-text-align-left" data-align="left">44.720%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">숫자 카드는 정수 하나가 적혀져 있는 카드이다. </p>



<p class="has-medium-font-size">상근이는 숫자 카드 N개를 가지고 있다.&nbsp;</p>



<p class="has-medium-font-size">정수 M개가 주어졌을 때, </p>



<p class="has-medium-font-size">이 수가 적혀있는 숫자 카드를 상근이가 가지고 있는지 아닌지를 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. </p>



<p class="has-medium-font-size">숫자 카드에 적혀있는 수는&nbsp;-10,000,000보다 크거나 같고, 10,000,000보다 작거나 같다. </p>



<p class="has-medium-font-size">두 숫자&nbsp;카드에 같은 수가 적혀있는 경우는 없다.</p>



<p class="has-medium-font-size">셋째 줄에는 M(1 ≤ M ≤ 500,000)이 주어진다. </p>



<p class="has-medium-font-size">넷째 줄에는 상근이가 가지고 있는 숫자 카드인지 아닌지를 구해야 할 M개의 정수가 주어지며, </p>



<p class="has-medium-font-size">이 수는 공백으로 구분되어져 있다. 이 수도&nbsp;-10,000,000보다 크거나 같고, 10,000,000보다 작거나 같다</p>



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



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



<p class="has-medium-font-size">첫째 줄에 입력으로 주어진 M개의 수에 대해서, </p>



<p class="has-medium-font-size">각&nbsp;수가 적힌 숫자 카드를&nbsp;상근이가 가지고 있으면 1을, 아니면 0을 공백으로 구분해 출력한다.</p>



<div style="height:40px" 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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
6 3 2 10 -10
8
10 9 -5 2 3 4 5 -10</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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1 0 0 1 1 0 0 1</pre>



<div style="height:60px" 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/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



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



<div style="height:40px" 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/97" target="_blank" rel="noreferrer noopener">정렬</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/12" 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)"/>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/01/image-53.png" alt="" class="wp-image-5867" width="626" height="463" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-53.png 820w, https://lycos7560.com/wp-content/uploads/2023/01/image-53-300x222.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-53-768x568.png 768w" sizes="(max-width: 626px) 100vw, 626px" /></figure>



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



<p class="has-medium-font-size">순회 형식으로 구현하면 숫자 하나를 확인할때 마다 500,000번의 연산이 필요하다. (시간 초과)</p>



<p class="has-medium-font-size">순회로 확인하는 방법보다 더 빠른 탐색 방법이 필요한데 </p>



<p class="has-medium-font-size">이럴 때 binary search를 이용하여 탐색의 시간 복잡도를 O(logN)으로 만들 수 있다.</p>



<p class="has-medium-font-size">코드는 재귀적으로 작성하였고 해설 참고하면 쉽게 이해가 가능하다.</p>



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



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



<div style="height:20px" 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;algorithm>

using namespace std;

constexpr int MAX = 500000;

int arr[MAX];

int N , M, target;

// 이분 탐색 함수
bool BinarySearch(int tArr[MAX], int start, int end, int target)
{
	if (start > end) return false; // 만족하는 결과가 없다 false return

	int mid = (start + end) / 2; // 중간 값을 찾아준다.

	if (arr[mid] == target)	return true; // 만족하는 결과!! true return

	// 찾는 수가 더 작다면, 검사 범위를 더 작게해서 다시 이분탐색 // 결과가 나오면 return
	// 찾는 수가 더 크면, 검사 범위를 더 크게해서 다시 이분탐색 // 결과가 나오면 return
	if (arr[mid] > target) return BinarySearch(arr, start, mid - 1, target);
	else return BinarySearch(arr, mid + 1, end, target);
}

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 >> arr[i];
	
	// 이분 탐색을 위한 오름차순 정렬을 수행한다.
	sort(arr, arr + N);

	// 탐색할 숫자의 개수를 입력받는다.
	cin >> M;

	for (int i = 0; i &lt; M; i++) {
		
		cin >> target;
		
		// 이진 탐색 후 출력
		cout &lt;&lt; BinarySearch(arr, 0, N - 1, target) &lt;&lt; "\n";

	}

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1037" height="99" src="https://lycos7560.com/wp-content/uploads/2023/01/image-52.png" alt="" class="wp-image-5863" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-52.png 1037w, https://lycos7560.com/wp-content/uploads/2023/01/image-52-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-52-768x73.png 768w" sizes="(max-width: 1037px) 100vw, 1037px" /></figure>



<div style="height:40px" 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/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/">백준 10815번 (숫자 카드, C++, Binary Search) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>cstdlib / C++ 표준 라이브러리 사용법 정리</title>
		<link>https://lycos7560.com/cpp/cstdlib-c-%ed%91%9c%ec%a4%80-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac-%ec%82%ac%ec%9a%a9%eb%b2%95-%ec%a0%95%eb%a6%ac/5776/</link>
					<comments>https://lycos7560.com/cpp/cstdlib-c-%ed%91%9c%ec%a4%80-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac-%ec%82%ac%ec%9a%a9%eb%b2%95-%ec%a0%95%eb%a6%ac/5776/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 31 Jan 2023 10:57:28 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[abort]]></category>
		<category><![CDATA[atof]]></category>
		<category><![CDATA[atoi]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[cstdlib]]></category>
		<category><![CDATA[exit]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[long long]]></category>
		<category><![CDATA[long long int]]></category>
		<category><![CDATA[malloc]]></category>
		<category><![CDATA[qsort]]></category>
		<category><![CDATA[rand]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[srand]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[strtol. strtoul]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[라이브러리]]></category>
		<category><![CDATA[문자열]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5776</guid>

					<description><![CDATA[<p>C++ 표준 라이브러리(STL) 'cstdlib'의 사용법을 정리한 글입니다. (This article summarizes the usage of the C++ Standard Library (STL) 'cstdlib'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/cstdlib-c-%ed%91%9c%ec%a4%80-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac-%ec%82%ac%ec%9a%a9%eb%b2%95-%ec%a0%95%eb%a6%ac/5776/">cstdlib / C++ 표준 라이브러리 사용법 정리</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:100px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-e62792df      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#cstdlib-c-표준-라이브러리" class="uagb-toc-link__trigger">cstdlib / C++ 표준 라이브러리</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#1-malloc-free-동적-메모리-할당-및-할당-해제에-사용됩니다" class="uagb-toc-link__trigger">1. malloc / free &#8211; 동적 메모리 할당 및 할당 해제에 사용됩니다</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#2-rand-srand-난수를-생성하는-데-사용됩니다" class="uagb-toc-link__trigger">2. rand / srand &#8211; 난수를 생성하는 데 사용됩니다</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#3-exit-프로그램-종료" class="uagb-toc-link__trigger">3. exit &#8211; 프로그램 종료</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#4-atoi-문자열을-정수로-변환하는-데-사용됩니다" class="uagb-toc-link__trigger">4. atoi &#8211; 문자열을 정수로 변환하는 데 사용됩니다</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#5-atof-문자열을-부동-소수점-번호로-변환하는-경우" class="uagb-toc-link__trigger">5. atof &#8211; 문자열을 부동 소수점 번호로 변환하는 경우</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#6-strtol-strtoll-long-및-long-long-integer-로-변환" class="uagb-toc-link__trigger">6. strtol / strtoll &#8211; Long 및 Long Long Integer 로 변환</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#strtoul-strtoull-부호없는-long-및-부호없는-long-long-integer로-변환" class="uagb-toc-link__trigger">strtoul / strtoull &#8211; 부호없는 Long 및 부호없는 Long Long Integer로 변환</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#7-system-시스템-명령을-실행합니다" class="uagb-toc-link__trigger">7. system &#8211; 시스템 명령을 실행합니다</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#8-abort-비정상적인-프로그램-종료를-강제합니다" class="uagb-toc-link__trigger">8. abort &#8211; 비정상적인 프로그램 종료를 강제합니다</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#9-qsort-배열을-정렬합니다" class="uagb-toc-link__trigger">9. qsort &#8211; 배열을 정렬합니다</a></ul></ol>					</div>
									</div>
				</div>
			


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



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



<h2 class="wp-block-heading">cstdlib / C++ 표준 라이브러리</h2>



<p><a href="https://learn.microsoft.com/ko-kr/cpp/standard-library/cstdlib?view=msvc-170" target="_blank" rel="noreferrer noopener">https://learn.microsoft.com/ko-kr/cpp/standard-library/cstdlib?view=msvc-170</a></p>



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



<p class="has-medium-font-size">cstdlib은 C++ 표준 라이브러리에 있는 라이브러리로</p>



<p class="has-medium-font-size"><strong>동적 메모리 관리, 난수 생성, 문자열을 숫자 값으로 변환하는 등의 일반적인 기능을 수행하기 위한 일련의 기능을 제공</strong>합니다.</p>



<p class="has-medium-font-size">라이브러리는 C++ 표준 라이브러리의 일부이며 cstdlib 헤더 파일에 정의되어 있습니다. </p>



<p class="has-medium-font-size">다양한 프로그래밍 컨텍스트에서 공통적이고 유용한 유틸리티 기능과 매크로 세트를 제공합니다. </p>



<p class="has-medium-font-size">cstdlib 라이브러리는 <strong>메모리 할당 및 프로세스 제어와 같은 낮은 수준의 작업을 수행하는 데 특히 유용</strong>합니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="893" height="191" src="https://lycos7560.com/wp-content/uploads/2023/01/image-51.png" alt="" class="wp-image-5843" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-51.png 893w, https://lycos7560.com/wp-content/uploads/2023/01/image-51-300x64.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-51-768x164.png 768w" sizes="(max-width: 893px) 100vw, 893px" /></figure>



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



<p class="has-medium-font-size">(cstdlib에서 가장 일반적으로 사용되는 함수)</p>



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



<p class="has-medium-font-size"><strong>malloc </strong>/ <strong>free</strong> &#8211; 동적 메모리 할당 및 할당 해제에 사용됩니다</p>



<p class="has-medium-font-size"><strong>rand</strong> /<strong> srand</strong> &#8211; 난수를 생성하는 데 사용됩니다</p>



<p class="has-medium-font-size"><strong>exit </strong>&#8211; 프로그램 종료</p>



<p class="has-medium-font-size"><strong>atoi </strong>&#8211; 문자열을 정수로 변환하는 데 사용됩니다</p>



<p class="has-medium-font-size"><strong>atof </strong>&#8211; 문자열을 부동 소수점 번호로 변환하는 경우</p>



<p class="has-medium-font-size"><strong>strtol</strong> / <strong>strtoul</strong> &#8211; 문자열을 긴 또는 부호 없는 긴 정수로 변환하는 데 사용됩니다</p>



<p class="has-medium-font-size"><strong>system</strong> &#8211; 시스템 명령을 실행합니다</p>



<p class="has-medium-font-size"><strong>abort</strong> &#8211; 비정상적인 프로그램 종료를 강제합니다</p>



<p class="has-medium-font-size"><strong>qsort </strong>&#8211; 배열을 정렬합니다</p>



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



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



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



<p class="has-medium-font-size"><strong>예제</strong></p>



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



<h3 class="wp-block-heading">1. malloc / free &#8211; 동적 메모리 할당 및 할당 해제에 사용됩니다</h3>



<div style="height:40px" 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;cstdlib>

int main() {

    int n;

    std::cout &lt;&lt; "할당할 정수 수 입력 : ";

    std::cin >> n;

    // 동적으로 메모리를 할당할때 Heap(힙)영역에 할당
    // 성공 : 할당한 메모리의 첫번째 주소 리턴
    // 실패 : NULL 리턴
    int* p = static_cast&lt;int*>(malloc(n * sizeof(int)));  // n개의 정수에 메모리 할당

    if (p == nullptr) { // NULL이 return되면 => 할당 실패

        std::cerr &lt;&lt; "오류: 메모리를 할당할 수 없습니다 " &lt;&lt; std::endl;

        return 1;

    }

    for (int i = 0; i &lt; n; i++) {

        p[i] = i;

    }

    std::cout &lt;&lt; "할당된 메모리에 다음 값이 포함되어 있습니다 : ";

    for (int i = 0; i &lt; n; i++) {

        std::cout &lt;&lt; p[i] &lt;&lt; ' ';

    }

    std::cout &lt;&lt; std::endl;

    // 메모리 할당 해제
    // 해제 안하면 메모리 릭, 메모리 누수가 발생
    free(p); 

    return 0;
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="967" height="110" src="https://lycos7560.com/wp-content/uploads/2023/01/image-47.png" alt="" class="wp-image-5805" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-47.png 967w, https://lycos7560.com/wp-content/uploads/2023/01/image-47-300x34.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-47-768x87.png 768w" sizes="(max-width: 967px) 100vw, 967px" /></figure>



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



<h3 class="wp-block-heading">2. rand / srand &#8211; 난수를 생성하는 데 사용됩니다</h3>



<div style="height:40px" 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;cstdlib>
#include &lt;ctime>

int main() {

    srand(time(nullptr));  // 현재 시간 seed로 난수 생성
    //srand(time(NULL));

    std::cout &lt;&lt; rand() &lt;&lt; std::endl;

    std::cout &lt;&lt; rand() &lt;&lt; std::endl;

    std::cout &lt;&lt; rand() &lt;&lt; std::endl;

    std::cout &lt;&lt; rand() &lt;&lt; std::endl;

    std::cout &lt;&lt; rand() &lt;&lt; std::endl;

    for (int i = 0; i &lt; 10; i++) {

        int randomNumber = rand() % 100;  // 0과 99 사이의 난수 생성

        std::cout &lt;&lt; randomNumber &lt;&lt; std::endl;

    }
    return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="257" height="277" src="https://lycos7560.com/wp-content/uploads/2023/01/image-46.png" alt="" class="wp-image-5800" style="width:278px;height:300px"/></figure>



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



<h3 class="wp-block-heading">3. exit &#8211; 프로그램 종료</h3>



<div style="height:40px" 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;cstdlib>

int main() {

	std::cout &lt;&lt; "Exiting program" &lt;&lt; std::endl;

	// 프로그램 종료
	std::exit(0);

	// 종료되어서 안나온다.
	std::cout &lt;&lt; "Do something!!";

	return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="430" height="348" src="https://lycos7560.com/wp-content/uploads/2023/01/image-45.png" alt="" class="wp-image-5794" style="width:525px;height:425px" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-45.png 430w, https://lycos7560.com/wp-content/uploads/2023/01/image-45-300x243.png 300w" sizes="(max-width: 430px) 100vw, 430px" /></figure>



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



<h3 class="wp-block-heading">4. atoi &#8211; 문자열을 정수로 변환하는 데 사용됩니다</h3>



<div style="height:40px" 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;cstdlib>

int main() {

	std::string str;

	std::cin >> str;

	// 변환이 불가능 하다면 0 return 
	int num = std::atoi(str.c_str());

	std::cout &lt;&lt; num &lt;&lt; std::endl;

	return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="574" height="190" src="https://lycos7560.com/wp-content/uploads/2023/01/image-48.png" alt="" class="wp-image-5809" style="width:666px;height:220px" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-48.png 574w, https://lycos7560.com/wp-content/uploads/2023/01/image-48-300x99.png 300w" sizes="(max-width: 574px) 100vw, 574px" /></figure>



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



<h3 class="wp-block-heading">5. atof &#8211; 문자열을 부동 소수점 번호로 변환하는 경우</h3>



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



<div style="height:0px" 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;cstdlib>

int main() {

	std::string str;

	std::cin >> str;

	// atof() 함수는 입력 문자를 숫자로 해석하여 생성되는 double 값을 리턴합니다. 
	// 함수가 입력을 해당 유형의 값으로 변환할 수 없는 경우 리턴값은 0입니다. 
	// 오버플로의 경우, 함수는 errno를 ERANGE로 설정하고 값 -HUGE_VAL 또는 +HUGE_VAL을 리턴합니다.
	// 변환이 불가능 하다면 0 return 
	float num = std::atof(str.c_str());

	std::cout &lt;&lt; num &lt;&lt; std::endl;

	return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="611" height="268" src="https://lycos7560.com/wp-content/uploads/2023/01/image-49.png" alt="" class="wp-image-5830" style="width:671px;height:294px" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-49.png 611w, https://lycos7560.com/wp-content/uploads/2023/01/image-49-300x132.png 300w" sizes="(max-width: 611px) 100vw, 611px" /></figure>



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



<h3 class="wp-block-heading">6. strtol / strtoll &#8211; Long 및 Long Long Integer 로 변환</h3>



<h3 class="wp-block-heading">strtoul / strtoull &#8211; 부호없는 Long 및 부호없는 Long Long Integer로 변환</h3>



<p>모두 같은 방법으로 사용</p>



<div style="height:40px" 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;cstdlib>
#include &lt;errno.h>

int main() {
    // 
    // ststol, strtoul, strtof, strtoll 사용법이 같다.
    // 
    // 이 예제에서는 strtoll 함수를 사용하여 문자열 "123456789"를 long long int로 변환합니다. 
    // 변환 결과는 num 변수에 저장된 다음 표준 출력으로 인쇄됩니다. 
    // 
    // strtoll 함수는 
    // 변환할 문자열, 문자열에 잘못된 첫 번째 문자의 주소를 저장할 문자에 대한 포인터, 
    // 숫자 표현의 기저(10진수의 경우 10진수)의 세 가지 인수를 사용합니다. 
    //
    // 변환이 실패하면 endptr 변수가 첫 번째 잘못된 문자를 가리키고 
    // num 변수에 유효한 숫자 표현이 포함되지 않습니다. 
    // 변환이 성공했는지 확인하기 위해 *endptr이 문자열의 끝을 나타내는 '\0'과 같은지 확인할 수 있습니다.

    const char* str = "123456789";

    char* endptr;

    long long num = strtoll(str, &amp;endptr, 10);

    if (*endptr != '\0') {

        std::cerr &lt;&lt; "Conversion failed: non-digit characters present" &lt;&lt; std::endl;

    }
    else {

        std::cout &lt;&lt; "The string " &lt;&lt; str &lt;&lt; " converted to a long long int is " &lt;&lt; num &lt;&lt; std::endl;

    }

    return 0;

}
</pre>



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



<h3 class="wp-block-heading">7. system &#8211; 시스템 명령을 실행합니다</h3>



<div style="height:40px" 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;cstdlib>

int main() {

	// 문자열 "Hello World"를 표준 출력으로 인쇄하는 명령인 
	// "echo Hello World" 인수로 호출
	// 시스템 메서드는 실행된 명령의 상태 코드를 반환


	// 0 성공
	int result = system("echo Hello World");

	std::cout &lt;&lt; "The result of the system call is: " &lt;&lt; result &lt;&lt; std::endl &lt;&lt; std::endl;


	result = system("wrong Hello World");
	// 1 실패
	std::cout &lt;&lt; "The result of the system call is: " &lt;&lt; result &lt;&lt; std::endl;


	return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="638" height="137" src="https://lycos7560.com/wp-content/uploads/2023/01/image-44.png" alt="" class="wp-image-5790" style="width:754px;height:162px" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-44.png 638w, https://lycos7560.com/wp-content/uploads/2023/01/image-44-300x64.png 300w" sizes="(max-width: 638px) 100vw, 638px" /></figure>



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



<h3 class="wp-block-heading">8. abort &#8211; 비정상적인 프로그램 종료를 강제합니다</h3>



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



<div style="height:20px" 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;cstdlib>

int main() {

	// 비정상적인 프로그램 종료 
	std::cout &lt;&lt; "Aborting program" &lt;&lt; std::endl;

	std::abort();

	return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="846" height="252" src="https://lycos7560.com/wp-content/uploads/2023/01/image-43.png" alt="" class="wp-image-5784" style="width:1042px;height:310px" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-43.png 846w, https://lycos7560.com/wp-content/uploads/2023/01/image-43-300x89.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-43-768x229.png 768w" sizes="(max-width: 846px) 100vw, 846px" /></figure>



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



<h3 class="wp-block-heading">9. qsort &#8211; 배열을 정렬합니다</h3>



<div style="height:40px" 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;cstdlib>

// qsort 함수는 정수 배열을 정렬하는 데 사용됩니다.
// qsort 함수는 배열의 첫 번째 요소에 대한 포인터, 배열의 요소 수, 배열의 각 요소의 크기, 
// 두 요소의 순서에 따라 0보다 작거나 같거나 큰 값을 반환하는 비교 함수의 네 가지 인수를 사용합니다.
// 비교 함수 비교는 배열의 요소에 대한 포인터인 두 개의 인수를 사용하고 두 포인터가 가리키는 값의 차이를 반환합니다.
// qsort 함수는 배열이 정렬될 때까지 순서가 잘못된 요소를 반복적으로 스왑하여 배열의 요소를 정렬합니다.
// 정렬 후 정렬된 배열이 표준 출력으로 인쇄됩니다


/*
compare 함수는 cstdlib 라이브러리의 qsort 함수가 요소 배열을 정렬하는 데 사용하는 비교 함수입니다.
compare 함수는 두 개의 인수를 사용하며, 각 인수는 배열의 요소에 대한 포인터입니다
*/
int compare(const void* a, const void* b) {
    int numA = *(int*)a;
    int numB = *(int*)b;
    return (numA - numB);
}
/*
비교 함수는 두 정수를 비교합니다.
먼저 각 인수를 int에 대한 포인터에 캐스팅한 다음 포인터를 역참조하여 정수의 값을 얻습니다.
그런 다음 두 정수의 차이를 반환합니다.
비교 함수의 반환 값은 비교 중인 두 요소의 순서를 결정합니다.
반환 값이 0보다 작으면 첫 번째 요소는 두 번째 요소보다 작은 것으로 간주됩니다.
반환 값이 0이면 첫 번째 요소는 두 번째 요소와 동일한 것으로 간주됩니다.
반환 값이 0보다 크면 첫 번째 요소가 두 번째 요소보다 큰 것으로 간주됩니다.
qsort 함수는 비교 함수를 사용하여 배열이 정렬될 때까지
순서가 잘못된 요소를 반복적으로 스왑하여 배열의 요소를 정렬합니다.
*/



int main() {

    int numbers[] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3 };

    int size = sizeof(numbers) / sizeof(numbers[0]);

    qsort(numbers, size, sizeof(int), compare);

    std::cout &lt;&lt; "Sorted array: ";

    for (int i = 0; i &lt; size; i++) {

        std::cout &lt;&lt; numbers[i] &lt;&lt; " ";

    }

    std::cout &lt;&lt; std::endl;

    return 0;
}
</pre>



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



<div class="wp-block-uagb-icon-list uagb-block-4a2a6457"><div class="uagb-icon-list__wrap"></div></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="434" height="63" src="https://lycos7560.com/wp-content/uploads/2023/01/image-50.png" alt="" class="wp-image-5841" style="width:710px;height:103px" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-50.png 434w, https://lycos7560.com/wp-content/uploads/2023/01/image-50-300x44.png 300w" sizes="(max-width: 434px) 100vw, 434px" /></figure>



<div style="height:100px" 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/cstdlib-c-%ed%91%9c%ec%a4%80-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac-%ec%82%ac%ec%9a%a9%eb%b2%95-%ec%a0%95%eb%a6%ac/5776/">cstdlib / C++ 표준 라이브러리 사용법 정리</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/cstdlib-c-%ed%91%9c%ec%a4%80-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac-%ec%82%ac%ec%9a%a9%eb%b2%95-%ec%a0%95%eb%a6%ac/5776/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 18870번 (좌표 압축, C++, Map) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 12:53:29 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[18870]]></category>
		<category><![CDATA[18870번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[sort]]></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[백준 18870]]></category>
		<category><![CDATA[백준 18870번]]></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=5547</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 18870번 '좌표 압축' 문제에 대한 글입니다. 'map' 자료구조를 이용하여 해결하였습니다. (This is an article about the problem of 'coordinate compression' in BAEKJOON 1880. I solved it using 'map' data structure.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/">백준 18870번 (좌표 압축, C++, Map) [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>



<h1 class="wp-block-heading">좌표 압축</h1>



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



<div style="height:40px" 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">512 MB</td><td class="has-text-align-left" data-align="left">54604</td><td class="has-text-align-left" data-align="left">22882</td><td class="has-text-align-left" data-align="left">17501</td><td class="has-text-align-left" data-align="left">39.800%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">수직선 위에 N개의 좌표 X<sub>1</sub>, X<sub>2</sub>, &#8230;, X<sub>N</sub>이 있다. 이 좌표에 좌표 압축을 적용하려고 한다.</p>



<p class="has-medium-font-size">X<sub>i</sub>를 좌표 압축한 결과 X&#8217;<sub>i</sub>의 값은 X<sub>i</sub>&nbsp;&gt; X<sub>j</sub>를 만족하는 서로 다른 좌표의 개수와 같아야 한다.</p>



<p class="has-medium-font-size">X<sub>1</sub>, X<sub>2</sub>, &#8230;, X<sub>N</sub>에 좌표 압축을 적용한 결과 X&#8217;<sub>1</sub>, X&#8217;<sub>2</sub>, &#8230;, X&#8217;<sub>N</sub>를 출력해보자.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 N이 주어진다.</p>



<p class="has-medium-font-size">둘째 줄에는 공백 한 칸으로 구분된 X<sub>1</sub>, X<sub>2</sub>, &#8230;, X<sub>N</sub>이 주어진다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 X&#8217;<sub>1</sub>, X&#8217;<sub>2</sub>, &#8230;, X&#8217;<sub>N</sub>을 공백 한 칸으로 구분해서 출력한다.</p>



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



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



<ul class="wp-block-list">
<li>1 ≤ N ≤ 1,000,000</li>



<li>-10<sup>9</sup>&nbsp;≤ X<sub>i</sub>&nbsp;≤ 10<sup>9</sup></li>
</ul>



<div style="height:40px" 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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
2 4 -10 4 -9</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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2 3 0 3 1</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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6
1000 999 1000 999 1000 999</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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1 0 1 0 1 0</pre>



<div style="height:60px" 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/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>
</ul>



<div style="height:40px" 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/97" target="_blank" rel="noreferrer noopener">정렬</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/161" 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)"/>



<h2 class="wp-block-heading">해결 방법</h2>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1329" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021.jpg" alt="" class="wp-image-5551" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021.jpg 1600w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021-300x249.jpg 300w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021-768x638.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021-1536x1276.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



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



<div style="height:20px" 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;map>

using namespace std;

int arrN[1000001];
int number[1000000];

map&lt;int, int> myMap;

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

	cin >> arrN[0];

	for (int i = 1; i &lt;= arrN[0]; i++) cin >> arrN[i];

	// map을 이용한 정렬 
	for (int i = 1; i &lt;= arrN[0]; i++) 
		myMap.insert(make_pair(arrN[i], 0)); 

	int cnt = 0;
	for (auto it = myMap.begin(); it != myMap.end(); it++) 
		it->second = cnt++;

	for (int i = 1; i &lt;= arrN[0]; i++) 
		cout &lt;&lt; myMap.find(arrN[i])->second &lt;&lt; " ";

	return 0;
}
</pre>



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



<p class="has-medium-font-size">항상 배열의 범위를 잘못 설정하여 컴파일 및 런타임 에러가 발생한다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1027" height="219" src="https://lycos7560.com/wp-content/uploads/image-1059.png" alt="" class="wp-image-5549" srcset="https://lycos7560.com/wp-content/uploads/image-1059.png 1027w, https://lycos7560.com/wp-content/uploads/image-1059-300x64.png 300w, https://lycos7560.com/wp-content/uploads/image-1059-768x164.png 768w" sizes="(max-width: 1027px) 100vw, 1027px" /></figure>



<div style="height:100px" 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/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/">백준 18870번 (좌표 압축, C++, Map) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11279번 (최대 힙, C++, Priority_Queue) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11279%eb%b2%88-%ec%b5%9c%eb%8c%80-%ed%9e%99-c-priority_queue-baekjoon/5430/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11279%eb%b2%88-%ec%b5%9c%eb%8c%80-%ed%9e%99-c-priority_queue-baekjoon/5430/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 24 Jan 2023 09:57:34 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11279]]></category>
		<category><![CDATA[11279번]]></category>
		<category><![CDATA[algorithm]]></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[heap]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[priority_queue]]></category>
		<category><![CDATA[PriorityQueue]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 11279]]></category>
		<category><![CDATA[백준 11279번]]></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=5430</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11279번 '최대 힙' 문제에 대한 글입니다. 'Priority_Queue' 자료구조를 이용하여 해결하였습니다. This is an article about the 'maximum heap' problem in BAEKJOON No. 11279. We solved it using the 'Priority_Queue' data structure.</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11279%eb%b2%88-%ec%b5%9c%eb%8c%80-%ed%9e%99-c-priority_queue-baekjoon/5430/">백준 11279번 (최대 힙, C++, Priority_Queue) [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>



<h1 class="wp-block-heading">최대 힙</h1>



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



<div style="height:40px" 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">56406</td><td class="has-text-align-left" data-align="left">25322</td><td class="has-text-align-left" data-align="left">19842</td><td class="has-text-align-left" data-align="left">46.689%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">널리 잘 알려진 자료구조 중 최대 힙이 있다. 최대 힙을 이용하여 다음과 같은 연산을 지원하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">1. 배열에 자연수 x를 넣는다.</p>



<p class="has-medium-font-size">2. 배열에서 가장 큰 값을 출력하고, 그 값을 배열에서 제거한다.</p>



<p class="has-medium-font-size">프로그램은 처음에 비어있는 배열에서 시작하게 된다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. </p>



<p class="has-medium-font-size">다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. </p>



<p class="has-medium-font-size">만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, </p>



<p class="has-medium-font-size">x가 0이라면 배열에서 가장 큰 값을 출력하고 그 값을 배열에서 제거하는 경우이다. </p>



<p class="has-medium-font-size">입력되는 자연수는 2<sup>31</sup>보다 작다.</p>



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



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



<p class="has-medium-font-size">입력에서 0이 주어진 회수만큼 답을 출력한다. </p>



<p class="has-medium-font-size">만약 배열이 비어 있는 경우인데 가장 큰 값을 출력하라고 한 경우에는 0을 출력하면 된다.</p>



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">13
0
1
2
0
0
3
2
1
0
0
0
0
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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0
2
1
3
2
1
0
0</pre>



<div style="height:60px" 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/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



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



<div style="height:40px" 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/1927" target="_blank" rel="noreferrer noopener">1927번. 최소 힙</a></li>



<li><a href="https://www.acmicpc.net/problem/11286" target="_blank" rel="noreferrer noopener">11286번. 절댓값 힙</a></li>
</ul>



<div style="height:40px" 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/59" 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)"/>



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="UdAs7q5SS9"><a href="https://lycos7560.com/?p=5415">백준 1927번 (최소 힙, C++, Priority_Queue) [BAEKJOON]</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 1927번 (최소 힙, C++, Priority_Queue) [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=5415&#038;embed=true#?secret=NEFYZBkhvK#?secret=UdAs7q5SS9" data-secret="UdAs7q5SS9" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



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



<p class="has-medium-font-size">1927번과 같은 문제 오름차순 / 내림차순 차이</p>



<p class="has-medium-font-size">1927번 코드에서 &#8211; 만 빼주면 정답</p>



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



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



<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;queue>

using namespace std;

priority_queue&lt;int> myPQ;

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;

		if (temp == 0 &amp;&amp; myPQ.empty()) { 
			cout &lt;&lt; 0 &lt;&lt; "\n";
			continue;
		}
		else if (temp == 0 &amp;&amp; !myPQ.empty()) {
			cout &lt;&lt; myPQ.top() &lt;&lt; "\n";
			myPQ.pop();
			continue;
		}

		myPQ.push(temp);
	}

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1040" height="96" src="https://lycos7560.com/wp-content/uploads/image-1047.png" alt="" class="wp-image-5435" srcset="https://lycos7560.com/wp-content/uploads/image-1047.png 1040w, https://lycos7560.com/wp-content/uploads/image-1047-300x28.png 300w, https://lycos7560.com/wp-content/uploads/image-1047-768x71.png 768w" sizes="(max-width: 1040px) 100vw, 1040px" /></figure>



<div style="height:40px" 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/%eb%b0%b1%ec%a4%80-11279%eb%b2%88-%ec%b5%9c%eb%8c%80-%ed%9e%99-c-priority_queue-baekjoon/5430/">백준 11279번 (최대 힙, C++, Priority_Queue) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11279%eb%b2%88-%ec%b5%9c%eb%8c%80-%ed%9e%99-c-priority_queue-baekjoon/5430/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1927번 (최소 힙, C++, Priority_Queue) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1927%eb%b2%88-%ec%b5%9c%ec%86%8c-%ed%9e%99-c-priority_queue-baekjoon/5415/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1927%eb%b2%88-%ec%b5%9c%ec%86%8c-%ed%9e%99-c-priority_queue-baekjoon/5415/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 24 Jan 2023 09:32:09 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1927]]></category>
		<category><![CDATA[1927번]]></category>
		<category><![CDATA[algorithm]]></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[heap]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[priority_queue]]></category>
		<category><![CDATA[PriorityQueue]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1927]]></category>
		<category><![CDATA[백준 1927번]]></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=5415</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1927번 '최소 힙' 문제에 대한 글입니다. 'Priority_Queue' 자료구조를 이용하여 해결하였습니다. (This article is about the 'minimum heap' problem, BAEKJOON 1927. We solved it using the 'Priority_Queue' data structure.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1927%eb%b2%88-%ec%b5%9c%ec%86%8c-%ed%9e%99-c-priority_queue-baekjoon/5415/">백준 1927번 (최소 힙, C++, Priority_Queue) [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>



<h1 class="wp-block-heading">최소 힙</h1>



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



<div style="height:40px" 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">56626</td><td class="has-text-align-left" data-align="left">26465</td><td class="has-text-align-left" data-align="left">20831</td><td class="has-text-align-left" data-align="left">48.812%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">널리 잘 알려진 자료구조 중 최소 힙이 있다. </p>



<p class="has-medium-font-size">최소 힙을 이용하여 다음과 같은 연산을 지원하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">1. 배열에 자연수 x를 넣는다.</p>



<p class="has-medium-font-size">2. 배열에서 가장 작은 값을 출력하고, 그 값을 배열에서 제거한다.</p>



<p class="has-medium-font-size">프로그램은 처음에 비어있는 배열에서 시작하게 된다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. </p>



<p class="has-medium-font-size">다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. </p>



<p class="has-medium-font-size">만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, </p>



<p class="has-medium-font-size">x가 0이라면 배열에서 가장 작은 값을 출력하고 그 값을 배열에서 제거하는 경우이다. </p>



<p class="has-medium-font-size">x는 2<sup>31</sup>보다 작은 자연수 또는 0이고, 음의 정수는 입력으로 주어지지 않는다.</p>



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



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



<p class="has-medium-font-size">입력에서 0이 주어진 횟수만큼 답을 출력한다. </p>



<p class="has-medium-font-size">만약 배열이 비어 있는 경우인데 가장 작은 값을 출력하라고 한 경우에는 0을 출력하면 된다.</p>



<div style="height:40px" 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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">9
0
12345678
1
2
0
0
0
0
32</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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0
1
2
12345678
0</pre>



<div style="height:60px" 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/developer_p" target="_blank" rel="noreferrer noopener">developer_p</a>,&nbsp;<a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a>,&nbsp;<a href="https://www.acmicpc.net/user/leethyun" target="_blank" rel="noreferrer noopener">leethyun</a></li>
</ul>



<div style="height:40px" 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/11279" target="_blank" rel="noreferrer noopener">11279번. 최대 힙</a></li>



<li><a href="https://www.acmicpc.net/problem/11286" target="_blank" rel="noreferrer noopener">11286번. 절댓값 힙</a></li>
</ul>



<div style="height:40px" 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/59" 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)"/>



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



<p class="has-medium-font-size">priority_queue는 큐에 있는 모든 원소 중에서 가장 큰 값이 Top을 유지하도록, 우선순위가 가장 크도록 설계되어 있다 </p>



<p class="has-medium-font-size">또한 우선순위 큐는 내부적으로 Heap이라는 자료구조를 사용한다. (직접 구현하려면 힘드니 STL 쓰자)</p>



<p class="has-medium-font-size">이를 이용하여 priority_queue에 자료를 넣을때 -1을 해주면 가장 작은 값이 TOP으로 정렬된다.</p>



<p class="has-medium-font-size">이를 이용하여 문제를 해결하였다. </p>



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



<div style="height:20px" 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;queue>

using namespace std;

priority_queue&lt;int> myPQ;

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;

		if (temp == 0 &amp;&amp; myPQ.empty()) { 
			cout &lt;&lt; 0 &lt;&lt; "\n";
			continue;
		}
		else if (temp == 0 &amp;&amp; !myPQ.empty()) {
			cout &lt;&lt; -myPQ.top() &lt;&lt; "\n";
			myPQ.pop();
			continue;
		}

		// 우선선위 큐를 이용하기 위해서  * -1 한 뒤에 넣어준다.
		myPQ.push(temp * -1);
	}

	return 0;
}</pre>



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



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1046.png" alt="" class="wp-image-5416" width="1179" height="50" srcset="https://lycos7560.com/wp-content/uploads/image-1046.png 1030w, https://lycos7560.com/wp-content/uploads/image-1046-300x13.png 300w, https://lycos7560.com/wp-content/uploads/image-1046-768x33.png 768w" sizes="(max-width: 1179px) 100vw, 1179px" /></figure>



<div style="height:100px" 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/%eb%b0%b1%ec%a4%80-1927%eb%b2%88-%ec%b5%9c%ec%86%8c-%ed%9e%99-c-priority_queue-baekjoon/5415/">백준 1927번 (최소 힙, C++, Priority_Queue) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1927%eb%b2%88-%ec%b5%9c%ec%86%8c-%ed%9e%99-c-priority_queue-baekjoon/5415/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1427번 (소트인사이드, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/1427-sort-inside-c-baekjoon/4584/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/1427-sort-inside-c-baekjoon/4584/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 15 Jan 2023 20:50:59 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1427]]></category>
		<category><![CDATA[1427번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[Sort Inside]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1427]]></category>
		<category><![CDATA[백준 1427번]]></category>
		<category><![CDATA[소트인사이드]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[정렬]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4584</guid>

					<description><![CDATA[<p>백준 1427번 "소트인사이드" 문제에 대한 글입니다. (This is Baekjun 1427, about the "Sort Inside" issue.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1427-sort-inside-c-baekjoon/4584/">백준 1427번 (소트인사이드, C++) [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"><a href="https://www.acmicpc.net/problem/1427" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1427</a></p>



<div style="height:36px" 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">68887</td><td class="has-text-align-left" data-align="left">44299</td><td class="has-text-align-left" data-align="left">37018</td><td class="has-text-align-left" data-align="left">64.656%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">배열을 정렬하는 것은 쉽다. 수가 주어지면, </p>



<p class="has-medium-font-size">그 수의 각 자리수를 내림차순으로 정렬해보자.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 정렬하려고 하는 수 N이 주어진다. </p>



<p class="has-medium-font-size">N은 1,000,000,000보다 작거나 같은 자연수이다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 자리수를 내림차순으로 정렬한 수를 출력한다.</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="">2143</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="">4321</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="">999998999</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="">999999998</pre>



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



<h2 class="wp-block-heading">예제 입력 3</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="">61423</pre>



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



<h2 class="wp-block-heading">예제 출력 3</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="">64321</pre>



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



<h2 class="wp-block-heading">예제 입력 4</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="">500613009</pre>



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



<h2 class="wp-block-heading">예제 출력 4</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="">965310000</pre>



<div style="height:60px" 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/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>빠진 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/bvba" target="_blank" rel="noreferrer noopener">bvba</a>, <a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a></li>
</ul>



<div style="height:52px" 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/158" target="_blank" rel="noreferrer noopener">문자열</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/97" 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">입력을 문자열로 받고 해당 문자열의 인덱스 0번부터 마지막까지 순회하면서</p>



<p class="has-medium-font-size">해당 숫자의 배열의 값을 1 추가해준다.  ex) arr[1]++; </p>



<p class="has-medium-font-size">위의 작업을 마친 이후에 arr[9] -> arr[0] 까지 순회하면서 출력해준다.</p>



<div style="height:45px" 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>

using namespace std;

string str;

int arr[10];

int main()
{
	cin >> str;

	for (int i = 0; i &lt; str.length(); i++)  arr[str[i] - '0']++;

	for (int i = 9; i >= 0; i--) {
		for (int j = 0; j &lt; arr[i]; j++)  cout &lt;&lt; i;
	}

	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="1036" height="102" src="https://lycos7560.com/wp-content/uploads/image-942.png" alt="" class="wp-image-4586" srcset="https://lycos7560.com/wp-content/uploads/image-942.png 1036w, https://lycos7560.com/wp-content/uploads/image-942-300x30.png 300w, https://lycos7560.com/wp-content/uploads/image-942-768x76.png 768w" sizes="(max-width: 1036px) 100vw, 1036px" /></figure>



<div style="height:58px" 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/1427-sort-inside-c-baekjoon/4584/">백준 1427번 (소트인사이드, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/1427-sort-inside-c-baekjoon/4584/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2108번 (통계학, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 15 Jan 2023 20:33:09 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2108]]></category>
		<category><![CDATA[2108번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2108]]></category>
		<category><![CDATA[백준 2108번]]></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=4578</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2108번 "통계학" 문제에 대한 글입니다. (This article is about the "Statistics" problem in BAEKJOON No. 2108.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/">백준 2108번 (통계학, C++) [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"><a href="https://www.acmicpc.net/problem/2108">https://www.acmicpc.net/problem/2108</a></p>



<div style="height:41px" 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">256 MB</td><td class="has-text-align-left" data-align="left">124496</td><td class="has-text-align-left" data-align="left">27685</td><td class="has-text-align-left" data-align="left">22260</td><td class="has-text-align-left" data-align="left">25.422%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">수를 처리하는 것은 통계학에서 상당히 중요한 일이다. </p>



<p class="has-medium-font-size">통계학에서 N개의 수를 대표하는 기본 통계 값에는 다음과 같은 것들이 있다. </p>



<p class="has-medium-font-size">단, N은 홀수라고 가정하자.</p>



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



<ol class="wp-block-list">
<li>산술평균 : N개의 수들의 합을 N으로 나눈 값</li>



<li>중앙값 : N개의 수들을 증가하는 순서로 나열했을 경우 그 중앙에 위치하는 값</li>



<li>최빈값 : N개의 수들 중 가장 많이 나타나는 값</li>



<li>범위 : N개의 수들 중 최댓값과 최솟값의 차이</li>
</ol>



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



<p class="has-medium-font-size">N개의 수가 주어졌을 때, </p>



<p class="has-medium-font-size">네 가지 기본 통계값을 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 수의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. </p>



<p class="has-medium-font-size">단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. </p>



<p class="has-medium-font-size">입력되는 정수의 절댓값은 4,000을 넘지 않는다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에는 산술평균을 출력한다. </p>



<p class="has-medium-font-size">소수점 이하 첫째 자리에서 반올림한 값을 출력한다.</p>



<p class="has-medium-font-size">둘째 줄에는 중앙값을 출력한다.</p>



<p class="has-medium-font-size">셋째 줄에는 최빈값을 출력한다. </p>



<p class="has-medium-font-size">여러 개 있을 때에는 최빈값 중 두 번째로 작은 값을 출력한다.</p>



<p class="has-medium-font-size">넷째 줄에는 범위를 출력한다.</p>



<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="">5
1
3
8
-2
2</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="">2
2
1
10</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="">1
4000</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="">4000
4000
4000
0</pre>



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



<h2 class="wp-block-heading">예제 입력 3</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
-3
-1
-2</pre>



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



<h2 class="wp-block-heading">예제 출력 3</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="">-2
-2
-1
2</pre>



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



<h2 class="wp-block-heading">예제 입력 4</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="">3
0
0
-1</pre>



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



<h2 class="wp-block-heading">예제 출력 4</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
0
0
1</pre>



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



<p class="has-medium-font-size">(0 + 0 + (-1)) / 3 = -0.333333&#8230; 이고 이를 첫째 자리에서 반올림하면 0이다. -0으로 출력하면 안된다.</p>



<div style="height:44px" 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/user/bjh3502" target="_blank" rel="noreferrer noopener">bjh3502</a>, <a href="https://www.acmicpc.net/user/bsyun0571" target="_blank" rel="noreferrer noopener">bsyun0571</a>, <a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a>, <a href="https://www.acmicpc.net/user/jungyh1509" target="_blank" rel="noreferrer noopener">jungyh1509</a>, <a href="https://www.acmicpc.net/user/palilo" target="_blank" rel="noreferrer noopener">palilo</a>, <a href="https://www.acmicpc.net/user/YunGoon" target="_blank" rel="noreferrer noopener">YunGoon</a></li>



<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a>, <a href="https://www.acmicpc.net/user/skynet">s</a><a href="https://www.acmicpc.net/user/skynet" target="_blank" rel="noreferrer noopener">k</a><a href="https://www.acmicpc.net/user/skynet">ynet</a></li>
</ul>



<div style="height:44px" 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/124" target="_blank" rel="noreferrer noopener">수학</a></li>



<li><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/97" target="_blank" rel="noreferrer noopener">정렬</a></li>
</ul>



<div style="height:37px" 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)"/>



<p class="has-medium-font-size">최빈값이 여러 개 있을 때에는 최빈값 중 두 번째로 작은 값을 출력하는 부분을 구현하느냐고 엄청 시간이 걸렸다.</p>



<p class="has-medium-font-size">최빈값이 같으면 리스트에 넣어서 순서를 계산하는 방식으로 처리했다.</p>



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



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



<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;algorithm>
#include &lt;cmath>
#include &lt;set>

using namespace std;

int N, tempI, tempK, temp, tempJ;
int arr[500001];
int number[8001];
long long int sumAll;
list&lt;float> myList; // 결과를 저장할 리스트
list&lt;float> myList2; 

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

	cin >> N;
	for (int i = 0; i &lt; N; i++) {
		cin >> arr[i]; // N만큼 입력을 받음
		if (arr[i] > 0) number[arr[i] + 4000]++; // 양수일 경우
		else number[arr[i] * -1]++;
	}
		
	for (int i = 0; i &lt; N; i++)  // 총합을 구함
		sumAll = sumAll + arr[i];

	// 1. 산술평균 : N개의 수들의 합을 N으로 나눈 값
	float tempN = sumAll;
	myList.push_back(floor((tempN / N) + 0.5));

	// 2. 중앙값 : N개의 수들을 증가하는 순서로 나열했을 경우 그 중앙에 위치하는 값
	sort(arr, arr + N); // 오름차순 정렬

	myList.push_back(arr[(0 + (N))/2]);

	// 3. 최빈값 : N개의 수들 중 가장 많이 나타나는 값
	tempK = 0, tempI = -9999, tempJ = 0;
	int first = 0, second = 0;
	for (int i = 0; i &lt; 8001; i++) {
		if (i &lt;= 4000) {
			if (number[i] > tempI ) {
				tempI = number[i];
				tempK = i * -1;
				myList2.clear();
				myList2.push_back(tempK);
			}
			else if (number[i] == tempI) {
				tempK = i * -1;
				myList2.push_back(tempK);
			}
		}
		else {
				if (number[i] > tempI) {
					tempI = number[i];
					tempN = i - 4000;
					myList2.clear();
					myList2.push_back(tempN);
				}
				else if (number[i] == tempI) {
					tempK = i - 4000;
					myList2.push_back(tempK);
				}
		}
	}

	myList2.sort();

	int size = myList2.size();
	int cnt = 0;

	if (size >= 2) cnt = 2;
	else cnt = 1;

	for (auto it = myList2.begin(); it != myList2.end(); it++) {
		cnt--;
		if (cnt == 0) {
			myList.push_back(*it);
			break;
		}
	}

	// 4. 범위 : N개의 수들 중 최댓값과 최솟값의 차이
	temp = arr[0] - arr[N-1];
	temp = abs(temp);
	myList.push_back(temp);


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

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1040" height="97" src="https://lycos7560.com/wp-content/uploads/image-941.png" alt="" class="wp-image-4580" srcset="https://lycos7560.com/wp-content/uploads/image-941.png 1040w, https://lycos7560.com/wp-content/uploads/image-941-300x28.png 300w, https://lycos7560.com/wp-content/uploads/image-941-768x72.png 768w" sizes="(max-width: 1040px) 100vw, 1040px" /></figure>



<div style="height:35px" 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/2108-statistics-c-binarysearch-baekjoon/4578/">백준 2108번 (통계학, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
