<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>hazelog</title>
        <link>https://velog.io/</link>
        <description></description>
        <lastBuildDate>Mon, 14 Feb 2022 02:03:30 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>hazelog</title>
            <url>https://images.velog.io/images/haze_log/profile/acf33891-8bc2-4171-99e3-82823f1d1903/사진.PNG</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. hazelog. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/haze_log" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[sudo apt-get update 에러]]></title>
            <link>https://velog.io/@haze_log/sudo-apt-get-update-%EC%97%90%EB%9F%AC</link>
            <guid>https://velog.io/@haze_log/sudo-apt-get-update-%EC%97%90%EB%9F%AC</guid>
            <pubDate>Mon, 14 Feb 2022 02:03:30 GMT</pubDate>
            <description><![CDATA[<pre><code>Err:4 https://download.docker.com/linux/ubuntu focal InRelease
  The following signatures couldn&#39;t be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
Hit:7 http://security.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://download.docker.com/linux/ubuntu focal InRelease: The following signatures couldn&#39;t be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/focal/InRelease  The following signatures couldn&#39;t be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
W: Some index files failed to download. They have been ignored, or old ones used instead.
</code></pre><p><code>sudo apt-get update</code> 도중 위와 같은 에러가 발생했다. 구글링을 통해 여러 방법을 시도해봤지만 에러가 해결되지 않았다. 그러던 중 같은 형식의 다른 에러를 발견했고, 그 방법을 내 에러에 적용하니 해결이 되었다. 
하루종일 구글링을 통해서도 이 방법을 발견하지 못했었으니, 나와 같은 에러를 겪고 있는 분들을 위해 글을 남기기로 했다.</p>
<h3 id="1-가장-보편적인-방법">1. 가장 보편적인 방법</h3>
<p>에러를 보면 PUBKEY가 없다고 뜨니 해당 PUBKEY를 추가해주면 된다.</p>
<pre><code>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys &lt;PUBKEY&gt;</code></pre><p><code>&lt;PUBKEY&gt;</code>에는 에러로그에 없다고 한 key를 넣어주면 된다. 나의 경우에는 7EA0A9C3F273FCD8를 넣어주면 된다.
-&gt; 실패</p>
<h3 id="2-구글링을-통해-찾은-또-다른-방법">2. 구글링을 통해 찾은 또 다른 방법</h3>
<p>현재 다운받아져 있는 파일의 버전이 ubuntu 버전과 맞지 않아 발생하는 문제일 수도 있다.</p>
<pre><code>cd /etc/apt
sudo vi sources.list</code></pre><p>sources.list 파일 안에 들어가서 <code>deb [arch=amd64] https://download.docker.com/linux/ubuntu</code> 로 시작하는 줄을 모두 주석(#)처리하고 <code>deb [arch=amd64] https://download.docker.com/linux/ubuntu eoan stable</code>를 추가했다.
참고로 나는 ubuntu 20.04 버전이다.
-&gt; 실패</p>
<h3 id="3-난-위-방법-모두-안되네-또-찾아보자---구글링">3. 난 위 방법 모두 안되네. 또 찾아보자 -&gt; 구글링</h3>
<p>이 글은 <code>PUBKEY 7EA0A9C3F273FCD8</code>만을 위한 방법은 아니다. 실제로 나는 하나의 에러만 난 것이 아니라 여러 군데에서 에러가 났기 때문에 이 방법을 사용했다. 파일을 지웠다가 다시 만드는 과정이기 때문에 이 방법은 넘기고 다음 방법으로 넘어가도 좋다.</p>
<p>참고 : <a href="https://serverfault.com/questions/851724/apt-key-add-on-debian-stretch-no-valid-openpgp-data-found">https://serverfault.com/questions/851724/apt-key-add-on-debian-stretch-no-valid-openpgp-data-found</a>
위 답변 글에서 하는 말을 보면 <code>/etc/apt/trusted.gpg</code> 파일이 손상되어서 그럴 수도 있다고 한다.
그래서 이 파일 안을 보았더니 엄청 복잡한 글자로 이루어져 있다. ㅋㅋ.. 분석할 생각은 접고 일단 저 글을 따라했다.</p>
<pre><code>sudo su
gpg --keyserver keyring.debian.org --recv-keys 8B48AD6246925553
cd /etc/apt
rm trusted.gpg
gpg --export 8B48AD646925553 &gt;&gt; trusted.gpg</code></pre><p>-&gt; 실패</p>
<h3 id="4-찐막">4. 찐막</h3>
<p>진짜 이 방법은 어느 블로그나 질문글을 찾아봐도 없던 방법이다.... 잘했어 나 자신
가장 간단한 방법..</p>
<pre><code>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg</code></pre><p>위 코드를 실행 후 <code>sudo apt-get update</code>를 해보면 제대로 동작되는 것을 볼 수 있다. 
나는 docker에서 에러가 났기때문에 위 코드를 쳤고, 다른 곳에서 에러가 발생하는 경우는 그에 맞는 key 추가 방법을 찾으면 된다.
-&gt; 성공!
<br>
<br>
끝! 이제 모두 즐코딩을 하러 가자!</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 10448. 유레카 이론]]></title>
            <link>https://velog.io/@haze_log/%EB%B0%B1%EC%A4%80-10448.-%EC%9C%A0%EB%A0%88%EC%B9%B4-%EC%9D%B4%EB%A1%A0</link>
            <guid>https://velog.io/@haze_log/%EB%B0%B1%EC%A4%80-10448.-%EC%9C%A0%EB%A0%88%EC%B9%B4-%EC%9D%B4%EB%A1%A0</guid>
            <pubDate>Wed, 29 Dec 2021 16:02:29 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/10448">https://www.acmicpc.net/problem/10448</a></p>
<p>단순 구현문제에서 규칙을 찾으려고 머리 싸맸던 문제
입력으로 주어진 자연수의 범위가 3&lt;=N&lt;=1000이었기 때문에 단순 구현을 하여도 시간초과가 나지 않는 문제였다. </p>
<p>자연수의 가장 큰 값이 1000이라는 것은 n*(n+1)/2 가 최대 1000까지 나온다는 말이고, 이때 n은 최대 44가 된다.</p>
<p>그래서 그냥 45칸의 배열을 만들고 거기에 삼각수 값을 넣은 후 3번의 for문을 돌리면 된다.</p>
<pre><code class="language-java">import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Boj_10448 {
    static int[] triNum = new int[45];

    public static void triangular_number(){
        for(int i=1; i&lt;45; i++){
            triNum[i] = i*(i+1)/2;
        }
    }

    public static boolean eureka(int N){
        for(int a=1; a&lt;45; a++){
            for(int b=1; b&lt;45; b++){
                for(int c=1; c&lt;45; c++){
                    if(triNum[a]+triNum[b]+triNum[c]==N) return true;
                }
            }
        }

        return false;
    }

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int T = Integer.parseInt(br.readLine());

        triangular_number();

        for(int t=0; t&lt;T; t++){
            int N = Integer.parseInt(br.readLine());

            if(eureka(N)) bw.write(&quot;1&quot;);
            else bw.write(&quot;0&quot;);

            bw.write(&quot;\n&quot;);
        }
        bw.flush();
    }
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 10989. 수 정렬하기 3]]></title>
            <link>https://velog.io/@haze_log/%EB%B0%B1%EC%A4%80-10989.-%EC%88%98-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B0-3</link>
            <guid>https://velog.io/@haze_log/%EB%B0%B1%EC%A4%80-10989.-%EC%88%98-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B0-3</guid>
            <pubDate>Tue, 14 Dec 2021 04:11:07 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/10989">https://www.acmicpc.net/problem/10989</a></p>
<h1 id="counting-정렬">Counting 정렬</h1>
<p>: 배열을 이용해서 빈도수를 센 후 출력하는 방식</p>
<h3 id="counting-정렬-방법">Counting 정렬 방법</h3>
<ol>
<li>빈도 수를 셀 count배열 선언</li>
<li>입력을 받으면서 count 증가</li>
</ol>
<h3 id="전체코드">전체코드</h3>
<pre><code class="language-java">import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Boj_10989 {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int N = Integer.parseInt(br.readLine());

        int[] cnt = new int[10001];

        for(int i=0; i&lt;N; i++){
            cnt[Integer.parseInt(br.readLine())]++;
        }
        for(int i=0; i&lt;10001; i++){
            for(int j=0; j&lt;cnt[i]; j++){
                bw.write(i+&quot;\n&quot;);
            }
        }

        bw.flush();
    }
}</code></pre>
<h3 id="주의할-점">주의할 점</h3>
<ol>
<li>주어진 시간 제한이 적었기 때문에 <code>Scanner</code>와 <code>println</code>보다는 <code>BufferedReader</code>와 <code>BufferedWriter</code>를 쓰는게 좋다.</li>
<li>나올 수를 모두 count해야하기 때문에 전 문제(<a href="https://velog.io/@haze_log/%EB%B0%B1%EC%A4%80-2751.-%EC%88%98-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B0-2">수 정렬하기2</a>)처럼 나올 수 있는 수의 범위가 큰 경우에는 사용하지 못한다.</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[백준 2751. 수 정렬하기 2]]></title>
            <link>https://velog.io/@haze_log/%EB%B0%B1%EC%A4%80-2751.-%EC%88%98-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B0-2</link>
            <guid>https://velog.io/@haze_log/%EB%B0%B1%EC%A4%80-2751.-%EC%88%98-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B0-2</guid>
            <pubDate>Tue, 14 Dec 2021 04:02:42 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.acmicpc.net/problem/2751">https://www.acmicpc.net/problem/2751</a></p>
<h1 id="merge-sort">Merge Sort</h1>
<p>: 하나의 리스트를 두개의 균등한 크기의 리스트로 분할하고 각각 정렬한 후 합치는 정렬방법이다.</p>
<h3 id="merge-sort-방법">Merge Sort 방법</h3>
<ol>
<li><strong>분할 (Divide)</strong> : 리스트를 2개의 균등한 크기의 리스트(부분리스트)로 나누는 과정</li>
<li><strong>정복 (Conquer)</strong> : 부분 리스트를 정렬한다.</li>
<li><strong>결합 (Combine)</strong> : 정렬된 2개의 부분리스트를 하나의 리스트로 합병한다.</li>
</ol>
<h3 id="merge-sort-코드">Merge Sort 코드</h3>
<ol>
<li>분할<pre><code class="language-java">int mid = (start+end)/2; // 리스트의 가운데 인덱스
mergesort(start, mid); // start~mid까지 분할
mergesort(mid+1, end); // mid+1~end까지 분할</code></pre>
</li>
<li>정복<pre><code class="language-java">int front = start;
int back = mid+1;
int index = front;
</code></pre>
</li>
</ol>
<p>// front나 back이 하나라도 유효 범위에 있다면
while(front&lt;=mid || back&lt;=end){ </p>
<pre><code>// back이 범위를 넘었거나, 
// front가 범위 안에 있으면서 arr[front]&lt; arr[back] 이라면
if(back&gt;end || (front&lt;=mid &amp;&amp; arr[front]&lt;arr[back])){
    temp[index++] = arr[front++];
}else{ // 그 외의 경우
    temp[index++] = arr[back++];
}</code></pre><p>}</p>
<pre><code>3. 결합
```java
for(int i=start; i&lt;=end; i++){
    arr[i]=temp[i];
}</code></pre><h3 id="전체코드">전체코드</h3>
<pre><code class="language-java">import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class Boj_2751 {

    static int[] arr;
    static int[] temp;
    static int N;
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        N = Integer.parseInt(br.readLine());
        arr = new int[N];
        temp = new int[N];

        for(int n=0; n&lt;N; n++){
            arr[n]=Integer.parseInt(br.readLine());
        }

        // sorting
        mergesort(0, N-1);

        // print
        for(int n=0; n&lt;N; n++){
            bw.write(arr[n]+&quot;\n&quot;);
        }

        bw.flush();

    }

    public static void mergesort(int start, int end){
        if(start&lt;end){
            int mid = (start+end)/2;
            mergesort(start, mid);
            mergesort(mid+1, end);

            int front = start;
            int back = mid+1;
            int index = front;

            while(front&lt;=mid || back&lt;=end){ 
                if(back&gt;end || (front&lt;=mid &amp;&amp; arr[front]&lt;arr[back])){
                    temp[index++] = arr[front++];
                }else{
                    temp[index++] = arr[back++];
                }
            }

            for(int i=start; i&lt;=end; i++){
                arr[i]=temp[i];
            }
        }
    }
}</code></pre>
<h3 id="시간-복잡도">시간 복잡도</h3>
<p>Best : $O(Nlog2N)$
Worst : $O(Nlog2N)$
Avg : $O(Nlog2N)$</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Swagger2 NumberFormatException]]></title>
            <link>https://velog.io/@haze_log/Swagger2-NumberFormatException</link>
            <guid>https://velog.io/@haze_log/Swagger2-NumberFormatException</guid>
            <pubDate>Sat, 20 Nov 2021 15:16:43 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p><strong><em>Trouble shooting</em></strong>
Swagger2 사용시 발생하는 NumberFormatException 해결</p>
</blockquote>
<p>이 문제는 사실 Error가 아니라 Warning으로 떠서 Swagger사용에는 문제가 없지만 Console창에 뜨는 Warning이 눈에 거슬려 해결방법을 찾았다.</p>
<h3 id="pomxml-maven">pom.xml (Maven)</h3>
<pre><code>&lt;!-- Swagger2 --&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.springfox&lt;/groupId&gt;
    &lt;artifactId&gt;springfox-swagger2&lt;/artifactId&gt;
    &lt;version&gt;2.9.2&lt;/version&gt;
    &lt;!-- solved NumberFormatException in swagger2 --&gt; 
    &lt;exclusions&gt; 
        &lt;exclusion&gt; 
            &lt;groupId&gt;io.swagger&lt;/groupId&gt; 
            &lt;artifactId&gt;swagger-annotations&lt;/artifactId&gt; 
        &lt;/exclusion&gt; 
        &lt;exclusion&gt; 
            &lt;groupId&gt;io.swagger&lt;/groupId&gt; 
            &lt;artifactId&gt;swagger-models&lt;/artifactId&gt; 
        &lt;/exclusion&gt; 
    &lt;/exclusions&gt;
&lt;/dependency&gt;</code></pre><p>기존에 있던 swagger2 dependency(springfox-swagger2)에 exclusions 부분을 추가한다.
이렇게 하면 이제 swagger를 사용한 controller에서 @Api, @ApiOperation 어노테이션에서 에러가 나게 된다. 
이는 방금 exclusion을 통해 swagger-annotations와 swagger-models를 제거해서 그런건데 이걸 해결하기 위해선 아래 dependency를 pom.xml에 추가하면 된다.</p>
<pre><code>&lt;!-- solved NumberFormatException in swagger2 --&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.swagger&lt;/groupId&gt;
    &lt;artifactId&gt;swagger-annotations&lt;/artifactId&gt;
    &lt;version&gt;1.5.21&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.swagger&lt;/groupId&gt;
    &lt;artifactId&gt;swagger-models&lt;/artifactId&gt;
    &lt;version&gt;1.5.21&lt;/version&gt;
&lt;/dependency&gt;</code></pre>]]></description>
        </item>
    </channel>
</rss>