<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>yun_in.log</title>
        <link>https://velog.io/</link>
        <description>코딩 공부 및 프로젝트 정리</description>
        <lastBuildDate>Tue, 23 Jan 2024 07:15:15 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>yun_in.log</title>
            <url>https://velog.velcdn.com/images/yun_in/profile/75f9cbb3-2a3a-465c-ae49-d78b445ec866/image.png</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. yun_in.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/yun_in" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[프로그래머스] LV1. [PCCE 기출문제] 10번 / 데이터 분석]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV1.-PCCE-%EA%B8%B0%EC%B6%9C%EB%AC%B8%EC%A0%9C-10%EB%B2%88-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EB%B6%84%EC%84%9D</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV1.-PCCE-%EA%B8%B0%EC%B6%9C%EB%AC%B8%EC%A0%9C-10%EB%B2%88-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EB%B6%84%EC%84%9D</guid>
            <pubDate>Tue, 23 Jan 2024 07:15:15 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p><a href="https://school.programmers.co.kr/learn/courses/30/lessons/250121">[프로그래머스] LV1. [PCCE 기출문제] 10번 / 데이터 분석</a></p>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;
int sort_index = 0;

bool compared(vector&lt;int&gt; &amp;a, vector&lt;int&gt; &amp;b){
    return a[sort_index] &lt; b[sort_index];
}

vector&lt;vector&lt;int&gt;&gt; solution(vector&lt;vector&lt;int&gt;&gt; data, string ext, int val_ext, string sort_by) {
    vector&lt;vector&lt;int&gt;&gt; answer;
    string title[4] = {&quot;code&quot;, &quot;date&quot;, &quot;maximum&quot;, &quot;remain&quot;};
    int ext_index = 0;
    for(int i = 0; i &lt; 4; i++){
        if(ext == title[i]){
            ext_index = i;
        }
        if (sort_by == title[i]){
            sort_index = i;
        }
    }

    for(int i = 0; i &lt; data.size(); i++){
        if (data[i][ext_index] &lt; val_ext){
            answer.push_back(data[i]);
        }
    }

    sort(answer.begin(), answer.end(), compared);

    return answer;
}</code></pre>
<h1 id="문제-풀이">문제 풀이</h1>
<h4 id="변수-정리">변수 정리</h4>
<p>sort_index - 정렬해야하는 기준이 위치한 인덱스 저장. 외부 함수에서도 사용하기 위해 전역변수 선언.
ext_index - 큰 값을 없애는데 사용하기 위해 저장.
title[4] - string 제목 순서대로 저장하여 index를 찾는데 사용.</p>
<h4 id="-함수">+ 함수</h4>
<p>compared() sort 정렬을 할 때 사용하려고 만듦.</p>
<h4 id="해설">해설</h4>
<p>for문으로 0-3변화하며 sort_index, ext_index를 찾는다.
for문으로 data를 돌며 val_ext보다 작은 값을 answer에 저장한다.
sort를 사용하여 정렬한다. 정렬을 할때 위에 생성한 compared함수를 사용한다.
compared함수는 sort_index를 비교해서 a, b중 작은 것을 bool로 알려준다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV1. 성격 유형 검사하기]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV1.-%EC%84%B1%EA%B2%A9-%EC%9C%A0%ED%98%95-%EA%B2%80%EC%82%AC%ED%95%98%EA%B8%B0</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV1.-%EC%84%B1%EA%B2%A9-%EC%9C%A0%ED%98%95-%EA%B2%80%EC%82%AC%ED%95%98%EA%B8%B0</guid>
            <pubDate>Tue, 16 Jan 2024 23:31:10 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p><a href="https://school.programmers.co.kr/learn/courses/30/lessons/118666">프로그래머스 LV1. 성격 유형 검사하기</a></p>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;map&gt;

using namespace std;

string solution(vector&lt;string&gt; survey, vector&lt;int&gt; choices) {
    string answer = &quot;&quot;;
    map&lt;char, int&gt; score;
    score[&#39;R&#39;] = 0;
    score[&#39;T&#39;] = 0;
    score[&#39;C&#39;] = 0;
    score[&#39;F&#39;] = 0;
    score[&#39;J&#39;] = 0;
    score[&#39;M&#39;] = 0;
    score[&#39;A&#39;] = 0;
    score[&#39;N&#39;] = 0;
    for(int i = 0; i &lt; survey.size(); i++){
        int sc = abs(choices[i] - 4);
        if (choices[i] &lt; 4){
            score[survey[i][0]] += sc;
        } else {
            score[survey[i][1]] += sc;
        }
    }

    if(score[&#39;R&#39;] &gt;= score[&#39;T&#39;]){
        answer += &quot;R&quot;;
    } else {
        answer += &quot;T&quot;;
    }

    if(score[&#39;C&#39;] &gt;= score[&#39;F&#39;]){
        answer += &quot;C&quot;;
    } else {
        answer += &quot;F&quot;;
    }

    if(score[&#39;J&#39;] &gt;= score[&#39;M&#39;]){
        answer += &quot;J&quot;;
    } else {
        answer += &quot;M&quot;;
    }

    if(score[&#39;A&#39;] &gt;= score[&#39;N&#39;]){
        answer += &quot;A&quot;;
    } else {
        answer += &quot;N&quot;;
    }
    return answer;
}</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<p>map을 사용한 풀이
map&lt;char, int&gt; score로 각 char마다 점수를 카운트하고 점수 비교를 통해 유형을 분류한다.</p>
<h4 id="풀이에서-아쉬운-점">풀이에서 아쉬운 점</h4>
<p>각 score를 비교하는 부분의 코드가 반복되는 코드인데 4번이나 들어가서 코드가 길어졌다.
또 map에 초기 값을 넣는 부분도 반복되는데 계속 들어가 있다.</p>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;map&gt;

using namespace std;

char MBTI[4][2] = {
    {&#39;R&#39;,&#39;T&#39;},
    {&#39;C&#39;,&#39;F&#39;},
    {&#39;J&#39;,&#39;M&#39;},
    {&#39;A&#39;,&#39;N&#39;}
};

string solution(vector&lt;string&gt; survey, vector&lt;int&gt; choices) {
    string ans = &quot;&quot;;
    map&lt;char,int&gt; score;

    for(int i = 0; i &lt; survey.size(); ++i){
        if(choices[i] &lt; 4){
            score[survey[i][0]] += (4 - choices[i]);
        } else{
            score[survey[i][1]] += (choices[i] - 4); 
        }
    }

    for(int i = 0; i &lt; 4; ++i){
        if(score[MBTI[i][0]] &gt;= score[MBTI[i][1]]) ans += MBTI[i][0];
        else ans += MBTI[i][1];
    }

    return ans;
}</code></pre>
<blockquote>
</blockquote>
<p>for문을 사용해서 반복되는 코드를 줄였다.</p>
<h3 id="여기에서-궁금한-것">여기에서 궁금한 것</h3>
<p>if에서 비교할 때 map에 key가 없어도 비교가 되는 것인가?
map에 int값을 넣을 때 0을 먼저 넣지 않고 += 연산을 통해 넣을 수 있는 것인가?
-&gt; 실행이 되는 것을 보면 상관 없는 것 같다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV1.[PCCE 기출문제] 9번 / 이웃한 칸]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV1.PCCE-%EA%B8%B0%EC%B6%9C%EB%AC%B8%EC%A0%9C-9%EB%B2%88-%EC%9D%B4%EC%9B%83%ED%95%9C-%EC%B9%B8</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV1.PCCE-%EA%B8%B0%EC%B6%9C%EB%AC%B8%EC%A0%9C-9%EB%B2%88-%EC%9D%B4%EC%9B%83%ED%95%9C-%EC%B9%B8</guid>
            <pubDate>Tue, 16 Jan 2024 05:36:12 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p><a href="https://school.programmers.co.kr/learn/courses/30/lessons/250125">프로그래머스 LV1.[PCCE 기출문제] 9번 / 이웃한 칸</a></p>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;

using namespace std;

int solution(vector&lt;vector&lt;string&gt;&gt; board, int h, int w) {
    int answer = 0;

    int dh[4] = {0, 1, -1, 0};
    int dw[4] = {1, 0, 0, -1};

    for(int i = 0; i &lt; 4; i++){
        if ((0 &lt;= h + dh[i]) &amp;&amp; (h + dh[i] &lt; board.size()) &amp;&amp; (0 &lt;= w+dw[i]) &amp;&amp; (w+dw[i] &lt; board[0].size())){
            if (board[h][w] == board[h+dh[i]][w+dw[i]]){
                answer++;
            }
        }
    }

    return answer;
}</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<h3 id="변수-정리">변수 정리</h3>
<p>answer - 같은 색의 개수를 저장할 변수
dh - h의 변화량
dw - w의 변화량</p>
<h3 id="해설">해설</h3>
<p>for문으로 0-3까지 i를 변화하며 dh, dw를 h, w에 합한다.
h+dh[i]가 0이상 board.size()이고, w+dw[i]가 0이상 board[0].size()이면 h, w와 같은지 비교한다.
비교했을 때 같으면 answer++, 아니면 변화없이 지나간다.</p>
<h3 id="오류-났을-때-상황">오류 났을 때 상황</h3>
<p>0이상이여서 기호를 &lt;= 를 사용했어야 했는데 &lt; 만 사용하여 풀이가 되지 않았었다.
기호를 잘 보고 사용해야한다.</p>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;

using namespace std;

int solution(vector&lt;vector&lt;string&gt;&gt; board, int h, int w) {
    int answer = 0;

    int dh[4] = {0, 1, -1, 0};
    int dw[4] = {1, 0, 0, -1};

    for(int i = 0; i &lt; 4; i++){
    int h_check = h + dh[i];
    int w_check = w + dw[i];
        if ((0 &lt;= h_check) &amp;&amp; (h_check &lt; board.size()) &amp;&amp; (0 &lt;= w_check) &amp;&amp; (w_check &lt; board[0].size())){
            if (board[h][w] == board[h_check][w_check]){
                answer++;
            }
        }
    }

    return answer;
}</code></pre>
<blockquote>
<p>내 풀이와 다른 점
변수로 h_check, w_chech를 만들어서 계속 반복해서 계산을 하지 않는다.
장기적으로 봤을 때 연산의 양이 줄어들고, 코드의 길이도 줄어든다.</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[[c++] 문제 풀이 때 본 사이트 들]]></title>
            <link>https://velog.io/@yun_in/c-%EB%AC%B8%EC%A0%9C-%ED%92%80%EC%9D%B4-%EB%95%8C-%EB%B3%B8-%EC%82%AC%EC%9D%B4%ED%8A%B8-%EB%93%A4</link>
            <guid>https://velog.io/@yun_in/c-%EB%AC%B8%EC%A0%9C-%ED%92%80%EC%9D%B4-%EB%95%8C-%EB%B3%B8-%EC%82%AC%EC%9D%B4%ED%8A%B8-%EB%93%A4</guid>
            <pubDate>Thu, 09 Nov 2023 06:59:17 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.tcpschool.com/cpp/intro">c++ 개요 등 기초 사항</a></p>
<p><a href="https://www.google.com/search?q=%EC%95%84%EC%8A%A4%ED%82%A4%EC%BD%94%EB%93%9C%ED%91%9C&amp;oq=dktm&amp;gs_lcrp=EgZjaHJvbWUqDwgDEEUYOxiDARixAxiABDIGCAAQRRg5MgwIARAAGBQYhwIYgAQyDQgCEAAYgwEYsQMYgAQyDwgDEEUYOxiDARixAxiABDIHCAQQABiABDINCAUQLhiDARixAxiABDINCAYQABiDARixAxiABDINCAcQLhiDARixAxiABDINCAgQABiDARixAxiABDINCAkQABiDARixAxiABNIBCDI5ODNqMGo3qAIAsAIA&amp;sourceid=chrome&amp;ie=UTF-8#vhid=r8tVxqp8TrQfxM&amp;vssid=l">아스키 코드</a></p>
<p><a href="https://psychoria.tistory.com/709">stoi</a></p>
<p><a href="https://blockdmask.tistory.com/363">reverse</a></p>
<p><a href="https://inspire12.tistory.com/6">string</a></p>
<p><a href="https://mangu.tistory.com/34">vector_remove</a></p>
<p><a href="https://rebro.kr/37">vector_container</a></p>
<p><a href="https://www.delftstack.com/ko/howto/cpp/add-int-to-string-cpp/">string to int</a></p>
<p><a href="https://life-with-coding.tistory.com/285">vector for</a></p>
<p><a href="https://blockdmask.tistory.com/333">stoi, stof 등</a></p>
<p><a href="https://www.techiedelight.com/ko/sort-characters-of-a-string-in-cpp/">string sort</a></p>
<p><a href="https://cplusplus.com/reference/string/to_string">to_string</a></p>
<p><a href="https://blockdmask.tistory.com/307">sqrt</a></p>
<p><a href="https://issac-min.tistory.com/28">cmath</a></p>
<p><a href="https://0xffffffff.tistory.com/51">누적합</a></p>
<p><a href="https://techiedelight.com/ko/replace-occurrences-character-string-cpp">replace</a></p>
<p><a href="https://notepad96.tistory.com/36">vector sort</a></p>
<p><a href="https://www.delftstack.com/ko/howto/cpp/sort-string-in-cpp/">string sort 사용자 지정</a></p>
<p><a href="https://novlog.tistory.com/entry/C-%EC%88%9C%EC%97%B4-%EA%B5%AC%ED%95%98%EB%8A%94-%ED%95%A8%EC%88%98-nextpermutation-prev-permutation">순열, 조합</a></p>
<p><a href="https://www.techiedelight.com/ko/extract-a-subvector-from-a-vector-in-cpp/">부분 vector</a></p>
<p><a href="https://ldgeao99.tistory.com/379">map</a></p>
<p><a href="https://modoocode.com/235">substr</a></p>
<p><a href="https://popawaw.tistory.com/39">string compare</a></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[c++] int to binary? binary to int?]]></title>
            <link>https://velog.io/@yun_in/c-int-to-binary-binary-to-int</link>
            <guid>https://velog.io/@yun_in/c-int-to-binary-binary-to-int</guid>
            <pubDate>Thu, 09 Nov 2023 02:13:16 GMT</pubDate>
            <description><![CDATA[<p>int를 binary로 변환하여 사용하여 연산을 진행한 후 다시 int로 변환하는 문제들을 많이 만났다. 특히 bit로 연산을 하는 경우도 많기 때문에 알아둘 필요성이 있다고 생각했다.</p>
<h1 id="int-to-binary">int to binary</h1>
<p>2가지 방법 존재</p>
<blockquote>
</blockquote>
<p><strong>1. bitset 컨테이너</strong>
선언 시 상수 사이즈 입력으로 임의의 넉넉한 사이즈로 생성
<strong>2. &gt;&gt; bit 연산</strong>
string의 덧셈 연산이 빈번하게 발생</p>
<h2 id="bitset">bitset</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;bitset&gt; # bitset 추가

using namespace std;

int main() {
    int num = 12345;

    const int n = 100; 
    # 1. 변환방법 1
    bitset&lt;n&gt; bs(num);
    string s = bs.to_string();

    # 2. 변환방법 2
    string binary = bitset&lt;n&gt; (num).to_string();

    return 0;
}</code></pre>
<p>결과 -&gt; 11000000111001</p>
<h2 id="bit-연산-사용">&gt;&gt; bit 연산 사용</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;bitset&gt;

using namespace std;

string to_binary(int num) {
    string s = &quot;&quot;;
    while (num &gt; 0) {
        if (num % 2 == 1) s = &quot;1&quot; + s;
        else s = &quot;0&quot; + s;
        num &gt;&gt;= 1;
    }
    return s;
}

int main(){
    int num = 12345;

    string s = to_binary(num);

    return 0;
}</code></pre>
<h1 id="binary-to-int">binary to int</h1>
<p>3가지 방법 존재</p>
<blockquote>
</blockquote>
<p><strong>1. stoi()</strong>
<strong>2. bitset 컨테이너</strong>
선언 시 상수 사이즈 입력으로 임의의 넉넉한 사이즈로 생성</p>
<h2 id="stoi">stoi()</h2>
<p>정수형
int stoi(const string&amp; str, size_t* idx = 0, int base = 10)
long stol(const string&amp; str, size_t* idx = 0, int base = 10)</p>
<p>3번째 인자가 진수 표현이므로 2를 넣으면 2진수를 int로 변환한다.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

int main() {
    string s = &quot;0011000000111001&quot;;

    int num = stoi(s, nullptr, 2);

    return 0;
}</code></pre>
<h2 id="bitset컨테이너">bitset컨테이너</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;bitset&gt;
using namespace std;

int main() {
    string s = &quot;0011000000111001&quot;;

    /* binart string to long */
    cout &lt;&lt; &quot;이진수 문자열 &quot; &lt;&lt; s &lt;&lt; &quot; 을 정수로\n&quot;;
    bitset&lt;100&gt; bs2(s);
    cout &lt;&lt; bs2.to_ulong() &lt;&lt; &quot;\n&quot;;

    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 예산]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%98%88%EC%82%B0</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%98%88%EC%82%B0</guid>
            <pubDate>Thu, 09 Nov 2023 01:42:02 GMT</pubDate>
            <description><![CDATA[<p>풀이 1</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int solution(vector&lt;int&gt; d, int budget) {
    int answer = 0;
    vector&lt;int&gt; index = {0};
    sort(d.begin(), d.end());
    answer += d[0];
    int i = 1;
    while (answer != budget){
        if (answer + d[i] &lt; budget){
            answer += d[i];
            index.push_back(i);
            i++;
        } else {
            answer -= d[index[index.size()-1]];
            index.pop_back();
        }
    }
    return answer;
}</code></pre>
<p>signal: aborted (core dumped) 에러 발생으로 불가능</p>
<p>풀이 2</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int solution(vector&lt;int&gt; d, int budget) {
    int answer = 0;
    vector&lt;int&gt; side(d.size(), 1);
    int sum = 0;
    for(int i = 0; i &lt; d.size(); i++){
        do {
            sum = 0;
            for (int j = 0; j &lt; d.size(); ++j) {
                if (side[j] != 0) {
                    sum += d[j];
                }
            }
            if (sum == budget){
                return d.size() - i;
            }
        } while (next_permutation(d.begin(), d.end()));
        side[i] = 0;
    }
    return answer;
}</code></pre>
<p>시간 초과 및 2, 6 테스트케이스 실패</p>
<p>풀이 3</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int solution(vector&lt;int&gt; d, int budget)
{
    int answer = 0;
    int total = 0;

    sort(d.begin(), d.end());

    for (int i = 0; i &lt; d.size(); i++)
    {
        if (total + d[i] &gt; budget)
            break;
        answer++;
        total += d[i];
    }

    return answer;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] 숫자의 표현]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%88%AB%EC%9E%90%EC%9D%98-%ED%91%9C%ED%98%84</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%88%AB%EC%9E%90%EC%9D%98-%ED%91%9C%ED%98%84</guid>
            <pubDate>Thu, 19 Oct 2023 08:23:50 GMT</pubDate>
            <description><![CDATA[<p>처음 작성한 코드</p>
<pre><code class="language-python">def solution(n):
    answer = 0
    nums = []
    for i in range(1, n+1):
        nums.append(0)
        for j in range(i):
            nums[j] += i
    return answer</code></pre>
<p>for 문으로 전체를 순환하며 동작. 2중 for 문으로 인하여 효율성 검사에서 시간 초과 발생.
따라서 for문을 2중으로 사용하지 않는 방향을 생각해야함.
for 문을 이중으로 사용할 때 n보다 큰 수라 생기면 삭제하는 것을 방향으로 작성하는 것이 좋을 것이라고 예상한다. 삭제를 하더라도 for 문으로 이중으로 사용하게 되는 것인데 의미가 있을까? 효율성에서 n제곱의 형태가 나오는 것은 아닐까?</p>
<p>두번째 작성한 코드</p>
<pre><code class="language-python">def solution(n):
    answer = 0
    nums = []
    for i in range(1, n+1):
        nums.append(0)
        for j in range(len(nums)):
            nums[j] += i
        while nums[0] &gt;= n:
            if nums[0] == n:
                answer += 1
            print(nums)
            del nums[0]
    return answer</code></pre>
<p>오류를 발생하며 동작을 안했다..
<span style="color: red">IndexError: list index out of range</span> 오류 발생.
오류 발생의 원인은 while nums[0] &gt;= n에서 발생한 것으로 보인다. 모든 것을 다 지우고도 nums[0]를 찾아서 일것으로 생각하고 있다.
그래서 이 부분을 바꾸고 다시 작성한 다음 코드이다.</p>
<p>세번째 작성한 코드</p>
<pre><code class="language-python">def solution(n):
    answer = 0
    nums = []
    for i in range(1, n+1):
        nums.append(0)
        for j in range(len(nums)):
            nums[j] += i
        while nums[0] &gt; n:
            del nums[0]
        if nums[0] == n:
                answer += 1
    return answer</code></pre>
<p>오류 없이 효율성 검사도 통과하였다.
nums가 처음 코드에선 계속 해서 더하고 이미 지나간 코드에도 값을 계속 더했기 때문에 for문을 돌아야하는 길이가 n만큼 계속 커졌던 것에 비해 이미 커져서 의미가 없어진 값들은 지워나가기 때문에 그만큼 for 문을 돌 필요성이 사라진다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로보노] AWS에 mySQL설치]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EB%B3%B4%EB%85%B8-AWS%EC%97%90-mySQL%EC%84%A4%EC%B9%98</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EB%B3%B4%EB%85%B8-AWS%EC%97%90-mySQL%EC%84%A4%EC%B9%98</guid>
            <pubDate>Mon, 28 Aug 2023 02:11:00 GMT</pubDate>
            <description><![CDATA[<p>앱에서 로그인을 하기 위해 사용자 정보를 mysql에 저장을 하고 저장되어 있는 정보를 사용해 로그인을 하는 것을 만들려고 한다.
그래서 aws서버에 mysql을 먼저 설치하고 사용하는 방법을 하나씩 해보면서 정리해보자!</p>
<ol>
<li><p>AWS EC2접속
터미널을 사용해서 AWS EC2에 접속한다.
<code>ssh -i &#39;키이름&#39; ubuntu@서버 주소</code>
(aws서버를 ubuntu로 열었기 때문에 ubuntu 작성)</p>
</li>
<li><p>업데이트 진행
<code>sudo apt-get update</code></p>
</li>
<li><p>MySQL 설치</p>
<pre><code>sudo apt-get install mysql-server</code></pre></li>
</ol>
<p>설치 후 버전 확인
Version: mysql  Ver 8.0.34-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))</p>
<ol start="4">
<li>mysql 접근
ec2에서 mysql에 접근한다.<pre><code>sudo mysql -u root -p</code></pre>설치 직후 비밀번호가 없어 그냥 Enter를 쳐서 접속한다.</li>
</ol>
<p>암호 수정, 설정
암호 설정 없이 EC2를 종료하면 찾지 못 한다. 초기화하는 방법은 있지만 힘들고, EC2 Instance 생성 작업부터 다시 시작해야 하는 상황이 발생할 수 있다.</p>
<p>MySQL 비밀번호 변경</p>
<pre><code class="language-sql">use mysql</code></pre>
<p>Database Changed이후</p>
<pre><code>// 5 버전 사용자
mysql&gt; update user set password=password(&quot;암호&quot;) where user=&quot;root&quot;;

// 8 버전 사용자
mysql&gt; alter user &quot;root&quot;@&quot;localhost&quot; identified with mysql_native_password by &quot;암호&quot;;</code></pre><p>버전이 8이므로 </p>
<pre><code class="language-sql">alter user &quot;root&quot;@&quot;localhost&quot; identified with mysql_native_password by &quot;암호&quot;;</code></pre>
<p>입력</p>
<p>비밀번호 적용</p>
<pre><code class="language-sql">FLUSH PRIVILEGES;</code></pre>
<ol start="5">
<li>외부 접속 허용(MySQL WorkBench 등 사용 위해)</li>
</ol>
<ul>
<li><p>ec2 최고 권한 부여받기</p>
<pre><code>sudo su</code></pre></li>
<li><p>mysqld.cnf로 이동</p>
<pre><code>cd /etc/mysql/mysql.conf.d/</code></pre></li>
<li><p>vi로 mysqld.cnf파일 열기</p>
<pre><code>vi mysqld.cnf</code></pre></li>
<li><p>bind-adrees 수정
bind-address를 찾아 수정</p>
</li>
</ul>
<p>127.0.0.1 자기자신만 접속되는 것을 모두 가능하도록 0.0.0.0으로 변경한다.</p>
<pre><code>bind-address = 0.0.0.0</code></pre><p>변경 후 esc를 누르고 :wq를 작성하여 저장하고 종료한다.</p>
<ol start="6">
<li>MySQL 서버 재시작
MySQL에 .cnf 파일이 변경되었기 때문에 서버를 재시작한다.<pre><code>service mysql restart</code></pre></li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로보노] 서버 AWS ubuntu 20.04 mosquitto 설치]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EB%B3%B4%EB%85%B8-%EC%84%9C%EB%B2%84</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EB%B3%B4%EB%85%B8-%EC%84%9C%EB%B2%84</guid>
            <pubDate>Mon, 14 Aug 2023 07:50:10 GMT</pubDate>
            <description><![CDATA[<p>설치해야할 목록</p>
<ol>
<li>mqtt broker 설치</li>
<li>mysql - 로그인에 사용</li>
<li>php - 로그인에 사용</li>
</ol>
<h1 id="mqtt-broker-설치">mqtt broker 설치</h1>
<p>mosquitto 설치</p>
<pre><code class="language-shell">sudo apt install mosquitto
sudo apt install mosquitto-clients</code></pre>
<p>mosquitto 실행</p>
<pre><code class="language-shell">sudo systemctl start mosquitto
sudo systemctl enable mosquitto</code></pre>
<p>pub &amp; sub </p>
<pre><code class="language-shell">mosquitto_sub -d -t 토픽이름</code></pre>
<pre><code class="language-shell">mosquitto_pub -d -t 토픽이름 -m &quot;메시지&quot;</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 수열과 구간 쿼리 4]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98%EC%97%B4%EA%B3%BC-%EA%B5%AC%EA%B0%84-%EC%BF%BC%EB%A6%AC-4</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98%EC%97%B4%EA%B3%BC-%EA%B5%AC%EA%B0%84-%EC%BF%BC%EB%A6%AC-4</guid>
            <pubDate>Mon, 07 Aug 2023 12:29:22 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수 배열 <code>arr</code>와 2차원 정수 배열 <code>queries</code>이 주어집니다. <code>queries</code>의 원소는 각각 하나의 <code>query</code>를 나타내며, <code>[s, e, k]</code> 꼴입니다.</p>
<p>각 <code>query</code>마다 순서대로 <code>s</code> ≤ <code>i</code> ≤ <code>e</code>인 모든 <code>i</code>에 대해 <code>i</code>가 <code>k</code>의 배수이면 <code>arr[i]</code>에 1을 더합니다.</p>
<p>위 규칙에 따라 <code>queries</code>를 처리한 이후의 <code>arr</code>를 return 하는 solution 함수를 완성해 주세요.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>1 ≤ <code>arr</code>의 길이 ≤ 1,000<ul>
<li>0 ≤ <code>arr</code>의 원소 ≤ 1,000,000</li>
</ul>
</li>
<li>1 ≤ <code>queries</code>의 길이 ≤ 1,000<ul>
<li>0 ≤ <code>s</code> ≤ <code>e</code> &lt; <code>arr</code>의 길이</li>
<li>0 ≤ <code>k</code> ≤ 5</li>
</ul>
</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">arr</th>
<th align="center">queries</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[0, 1, 2, 4, 3]</td>
<td align="center">[[0, 4, 1],[0, 3, 2],[0, 3, 3]]</td>
<td align="center">[3, 2, 4, 6, 4]</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>각 쿼리에 따라 <code>arr</code>가 다음과 같이 변합니다.</li>
</ul>
<table>
<thead>
<tr>
<th align="center">arr</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[0, 1, 2, 4, 3]</td>
</tr>
<tr>
<td align="center">[1, 2, 3, 5, 4]</td>
</tr>
<tr>
<td align="center">[2, 2, 4, 5, 4]</td>
</tr>
<tr>
<td align="center">[3, 2, 4, 6, 4]</td>
</tr>
<tr>
<td align="center">- 따라서 [3, 2, 4, 6, 4]를 return 합니다.</td>
</tr>
<tr>
<td align="center">※ 2023년 04월 27일 입출력 예 설명이 수정되었습니다.</td>
</tr>
</tbody></table>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(arr, queries):
    answer = arr[:]
    for query in queries:
        for i in range(query[0], query[1]+1):
            if (i % query[2]) == 0:
                answer[i] += 1
    return answer</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>answer로 arr을 복사해서 넣는다.
(그냥 answer = arr로 하면 동일하게 두 값이 모두 바뀐다)</li>
<li>for문으로 queries를 돈다.</li>
<li>for문을 한번 더 돌며 query[0]부터 query[1]+1까지 동자하게 한다. i값이 query[2]로 나누어 떨어지면 answer[i]의 숫자를 하나 더한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(arr, queries):
    for s, e, k in queries:
        for i in range(s, e+1):
            if i%k == 0:
                arr[i] += 1
    return arr</code></pre>
<ul>
<li>for문으로 queries를 돈다.</li>
<li>for문을 한번 더 돌며 s부터 e+1까지 동자하게 한다. i값이 k로 나누어 떨어지면 arr[i]의 숫자를 하나 더한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Ubuntu] Ubuntu 20.04 카카오톡 설치하기]]></title>
            <link>https://velog.io/@yun_in/Ubuntu-Ubuntu-20.04-%EC%B9%B4%EC%B9%B4%EC%98%A4%ED%86%A1-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0</link>
            <guid>https://velog.io/@yun_in/Ubuntu-Ubuntu-20.04-%EC%B9%B4%EC%B9%B4%EC%98%A4%ED%86%A1-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0</guid>
            <pubDate>Mon, 07 Aug 2023 07:33:38 GMT</pubDate>
            <description><![CDATA[<p>카카오톡이 안 되서 너무 불편했다. 카톡으로 필요한 링크와 구매 물품들을 공유하는데 안되서 매번 불편함이 지속 되었다. 그래서 결국 카카오톡을 설치해서 편하게 사용하려고 한다.</p>
<h1 id="1-wine설치">1. Wine설치</h1>
<p>sudo dpkg --add-architecture i386</p>
<p>설치하다가 실패.....
안 돌아간다.
왜지????</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스]  LV0. 수열과 구간 쿼리 2]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98%EC%97%B4%EA%B3%BC-%EA%B5%AC%EA%B0%84-%EC%BF%BC%EB%A6%AC-2</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98%EC%97%B4%EA%B3%BC-%EA%B5%AC%EA%B0%84-%EC%BF%BC%EB%A6%AC-2</guid>
            <pubDate>Sun, 06 Aug 2023 04:41:19 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수 배열 <code>arr</code>와 2차원 정수 배열 <code>queries</code>이 주어집니다. <code>queries</code>의 원소는 각각 하나의 <code>query</code>를 나타내며, <code>[s, e, k]</code> 꼴입니다.</p>
<p>각 <code>query</code>마다 순서대로 <code>s</code> ≤ <code>i</code> ≤ <code>e</code>인 모든 <code>i</code>에 대해 <code>k</code>보다 크면서 가장 작은 <code>arr[i]</code>를 찾습니다.</p>
<p>각 쿼리의 순서에 맞게 답을 저장한 배열을 반환하는 solution 함수를 완성해 주세요.
단, 특정 쿼리의 답이 존재하지 않으면 -1을 저장합니다.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>1 ≤ <code>arr</code>의 길이 ≤ 1,000<ul>
<li>0 ≤ <code>arr</code>의 원소 ≤ 1,000,000</li>
</ul>
</li>
<li>1 ≤ <code>queries</code>의 길이 ≤ 1,000<ul>
<li>0 ≤ <code>s</code> ≤ <code>e</code> &lt; <code>arr</code>의 길이</li>
<li>0 ≤ <code>k</code> ≤ 1,000,000</li>
</ul>
</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">arr</th>
<th align="center">queries</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[0, 1, 2, 4, 3]</td>
<td align="center">[[0, 4, 2],[0, 3, 2],[0, 2, 2]]</td>
<td align="center">[3, 4, -1]</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>첫 번째 쿼리의 범위에는 0, 1, 2, 4, 3이 있으며 이 중 2보다 크면서 가장 작은 값은 3입니다.</li>
<li>두 번째 쿼리의 범위에는 0, 1, 2, 4가 있으며 이 중 2보다 크면서 가장 작은 값은 4입니다.</li>
<li>세 번째 쿼리의 범위에는 0, 1, 2가 있으며 여기에는 2보다 큰 값이 없습니다.</li>
<li>따라서 [3, 4, -1]을 return 합니다.</li>
</ul>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(arr, queries):
    answer = []
    for query in queries:
        up_k = []
        for i in range(query[0], query[1]+1):
            if arr[i] &gt; query[2]:
                up_k.append(arr[i])
        if len(up_k) == 0:
            answer.append(-1)
        else:
            answer.append(min(up_k))
    return answer</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>for문으로 queries를 돈다.</li>
<li>up_k 빈 리스트를 만든다.</li>
<li>for문으로 query[0]부터 query[1]까지 돌며 arr[i]가 query[2]보다 큰지 확인한다.</li>
<li>더 크다면 up_k에 append()를 사용해 arr[i]값을 추가한다.</li>
<li>up_k가 빈리스트가 빈 리스트이면 -1을 answer에 추가</li>
<li>빈 리스트가 아니면 up_k중 가장 작은값 min()을 answer에 추가한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(arr, queries):
    answer = []
    for s, e, k in queries:
        tmp = []
        for x in arr[s:e+1]:
            if x &gt; k:
                tmp.append(x)
        answer.append(-1 if not tmp else min(tmp))
    return answer</code></pre>
<ul>
<li>queries의 값을 받을 때 s,e,k로 받아서 따로 인덱싱을 할 필요가 없다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 수열과 구간 쿼리 3]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98%EC%97%B4%EA%B3%BC-%EA%B5%AC%EA%B0%84-%EC%BF%BC%EB%A6%AC-3</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98%EC%97%B4%EA%B3%BC-%EA%B5%AC%EA%B0%84-%EC%BF%BC%EB%A6%AC-3</guid>
            <pubDate>Sun, 06 Aug 2023 04:04:31 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수 배열 <code>arr</code>와 2차원 정수 배열 <code>queries</code>이 주어집니다. <code>queries</code>의 원소는 각각 하나의 <code>query</code>를 나타내며, <code>[i, j]</code> 꼴입니다.</p>
<p>각 <code>query</code>마다 순서대로 <code>arr[i]</code>의 값과 <code>arr[j]</code>의 값을 서로 바꿉니다.</p>
<p>위 규칙에 따라 <code>queries</code>를 처리한 이후의 <code>arr</code>를 return 하는 solution 함수를 완성해 주세요.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>1 ≤ <code>arr</code>의 길이 ≤ 1,000<ul>
<li>0 ≤ <code>arr</code>의 원소 ≤ 1,000,000</li>
</ul>
</li>
<li>1 ≤ <code>queries</code>의 길이 ≤ 1,000<ul>
<li>0 ≤ <code>i</code> &lt; <code>j</code> &lt; <code>arr</code>의 길이</li>
</ul>
</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">arr</th>
<th align="center">queries</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[0, 1, 2, 3, 4]</td>
<td align="center">[[0, 3],[1, 2],[1, 4]]</td>
<td align="center">[3, 4, 1, 0, 2]</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>각 쿼리에 따라 <code>arr</code>가 다음과 같이 변합니다.<pre><code>arr
[0, 1, 2, 3, 4]
[3, 1, 2, 0, 4]
[3, 2, 1, 0, 4]
[3, 4, 1, 0, 2]</code></pre></li>
<li>따라서 [3, 4, 1, 0, 2]를 return 합니다.</li>
</ul>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(arr, queries):
    for i in queries:
        sw = arr[i[0]]
        arr[i[0]] = arr[i[1]]
        arr[i[1]] = sw
    return arr</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>for문으로 queries를 돈다.</li>
<li>sw 에 i에 해당하는 arr 값을 담는다. arr[i[0]]</li>
<li>arr[i[0]]에 j에 해당하는 arr값을 넣는다. arr[i[1]]</li>
<li>arr[i[1]]에 i에 해당하는 값을 저장한 sw를 넣는다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(arr, queries):
    for a,b in queries:
        arr[a],arr[b]=arr[b],arr[a]
    return arr</code></pre>
<ul>
<li>for문으로 queries를 돌 때 query의 각 값을 a, b로 넣는다.</li>
<li>arr[a], arr[b] = arr[b], arr[a]로 작성하여 arr[a]에 arr[b]를, arr[b]에 arr[a]를 넣는다. </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 수 조작하기 2]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98-%EC%A1%B0%EC%9E%91%ED%95%98%EA%B8%B0-2</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98-%EC%A1%B0%EC%9E%91%ED%95%98%EA%B8%B0-2</guid>
            <pubDate>Sun, 06 Aug 2023 03:49:58 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수 배열 <code>numLog</code>가 주어집니다. 처음에 <code>numLog[0]</code>에서 부터 시작해 &quot;w&quot;, &quot;a&quot;, &quot;s&quot;, &quot;d&quot;로 이루어진 문자열을 입력으로 받아 순서대로 다음과 같은 조작을 했다고 합시다.</p>
<ul>
<li>&quot;w&quot; : 수에 1을 더한다.</li>
<li>&quot;s&quot; : 수에 1을 뺀다.</li>
<li>&quot;d&quot; : 수에 10을 더한다.</li>
<li>&quot;a&quot; : 수에 10을 뺀다.
그리고 매번 조작을 할 때마다 결괏값을 기록한 정수 배열이 <code>numLog</code>입니다. 즉, <code>numLog[i]</code>는 <code>numLog[0]</code>로부터 총 <code>i</code>번의 조작을 가한 결과가 저장되어 있습니다.</li>
</ul>
<p>주어진 정수 배열 <code>numLog</code>에 대해 조작을 위해 입력받은 문자열을 return 하는 solution 함수를 완성해 주세요.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>2 ≤ <code>log</code>의 길이 ≤ 100,000<ul>
<li>-100,000 ≤ <code>log[0]</code> ≤ 100,000</li>
<li>1 ≤ <code>i</code> ≤ <code>log</code>의 길이인 모든 <code>i</code>에 대해 <code>|log[i] - log[i - 1]|</code>의 값은 1 또는 10입니다.</li>
</ul>
</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">log</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[0, 1, 0, 10, 0, 1, 0, 10, 0, -1, -2, -1]</td>
<td align="center">&quot;wsdawsdassw&quot;</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>result인 &quot;wsdawsdassw&quot;를 따라 <code>log[0]</code>에서부터 시작해 조작을 하면 <code>log</code>의 값과 순서대로 일치합니다. 따라서 &quot;wsdawsdassw&quot;를 return 합니다.</li>
</ul>
<p>Hint
&quot;수 조작하기 1&quot; 문제의 <code>n</code>값이 <code>log[0]</code>에 해당하며, 이 문제에서 주어진 <code>log</code>에 따라 &quot;수 조작하기 1&quot; 문제의 <code>control</code>을 구하는 문제라고 이해할 수 있습니다.</p>
<p>입출력 예 #1은 &quot;수 조작하기 1&quot; 문제의 입출력 예 #1과 같은 예시이므로 참고하시기 바랍니다.</p>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(numLog):
    answer = &#39;&#39;
    for i in range(1, len(numLog)):
        if (numLog[i] - numLog[i - 1]) == 1:
            answer += &#39;w&#39;
        elif (numLog[i] - numLog[i - 1]) == -1:
            answer += &#39;s&#39;
        elif (numLog[i] - numLog[i - 1]) == 10:
            answer += &#39;d&#39;
        else:
            answer += &#39;a&#39;
    return answer</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>for문을 돈다. 값을 앞에 있는 수를 빼야하기 때문에 0부터가 아닌 1부터 for문을 돌게한다.</li>
<li>if - elif - else문을 사용하여 차가 1, -1, 10, -10을 판단하여 문자열에 더한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(log):
    res=&#39;&#39;
    joystick=dict(zip([1,-1,10,-10],[&#39;w&#39;,&#39;s&#39;,&#39;d&#39;,&#39;a&#39;]))
    for i in range(1,len(log)):
        res+=joystick[log[i]-log[i-1]]
    return res</code></pre>
<ul>
<li>딕셔너리를 사용한다.</li>
<li>joystick이라는 딕셔너리를 만든다. dict(), zip()을 이용해서 각 숫자마다 문자를 지정한다.</li>
<li>for문을 돌며 joystick[log[i]-log[i-1]]로 차 값에 해당하는 문자를 찾고 이를 문자열에 더한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 수 조작하기 1]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98-%EC%A1%B0%EC%9E%91%ED%95%98%EA%B8%B0-1</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%88%98-%EC%A1%B0%EC%9E%91%ED%95%98%EA%B8%B0-1</guid>
            <pubDate>Sun, 06 Aug 2023 03:38:23 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수 <code>n</code>과 문자열 <code>control</code>이 주어집니다. <code>control</code>은 &quot;w&quot;, &quot;a&quot;, &quot;s&quot;, &quot;d&quot;의 4개의 문자로 이루어져 있으며, <code>control</code>의 앞에서부터 순서대로 문자에 따라 <code>n</code>의 값을 바꿉니다.</p>
<ul>
<li>&quot;w&quot; : <code>n</code>이 1 커집니다.</li>
<li>&quot;s&quot; : <code>n</code>이 1 작아집니다.</li>
<li>&quot;d&quot; : <code>n</code>이 10 커집니다.</li>
<li>&quot;a&quot; : <code>n</code>이 10 작아집니다.
위 규칙에 따라 <code>n</code>을 바꿨을 때 가장 마지막에 나오는 <code>n</code>의 값을 return 하는 solution 함수를 완성해 주세요.</li>
</ul>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>-100,000 ≤ <code>n</code> ≤ 100,000</li>
<li>1 ≤ <code>control</code>의 길이 ≤ 100,000<ul>
<li><code>control</code>은 알파벳 소문자 &quot;w&quot;, &quot;a&quot;, &quot;s&quot;, &quot;d&quot;로 이루어진 문자열입니다.</li>
</ul>
</li>
</ul>
<p>입출력 예</p>
<table>
<thead>
<tr>
<th align="center">n</th>
<th align="center">control</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">0</td>
<td align="center">&quot;wsdawsdassw&quot;</td>
<td align="center">-1</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>수 n은 control에 따라 다음과 같은 순서로 변하게 됩니다.</li>
<li>0 → 1 → 0 → 10 → 0 → 1 → 0 → 10 → 0 → -1 → -2 → -1</li>
<li>따라서 -1을 return 합니다.</li>
</ul>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(n, control):
    answer = n + control.count(&#39;w&#39;) - control.count(&#39;s&#39;) + 10 * control.count(&#39;d&#39;) - 10 * control.count(&#39;a&#39;)
    return answer</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>각 알파벳마다 개수를 카운트한다. <code>.count()</code></li>
<li>알파벳마다 주어진 값에 따라 +1, -1, 10, -10을 곱해서 n과 함께 더한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<p>1.</p>
<pre><code class="language-python">def solution(n, control):
    key = dict(zip([&#39;w&#39;,&#39;s&#39;,&#39;d&#39;,&#39;a&#39;], [1,-1,10,-10]))
    return n + sum([key[c] for c in control])</code></pre>
<p>2.</p>
<pre><code class="language-python">def solution(n, control):
    answer = n
    c = { &#39;w&#39;:1, &#39;s&#39;:-1, &#39;d&#39;:10, &#39;a&#39;:-10}
    for i in control:
        answer += c[i]
    return answer</code></pre>
<ul>
<li>위 두 코드는 딕셔너리를 사용한다.</li>
<li>for 문을 돌면서 control에 있는 문자를 보고 해당하는 값을 더한다.</li>
</ul>
<ol>
<li>에서 딕셔너리를 만드는 방법은 dict()함수를 사용한다.
또 dict()안에 zip()으로 [&#39;w&#39;,&#39;s&#39;,&#39;d&#39;,&#39;a&#39;], [1,-1,10,-10]을 묶어 { &#39;w&#39;:1, &#39;s&#39;:-1, &#39;d&#39;:10, &#39;a&#39;:-10}이렇게 나열되도록 한다.
따라서 2.의 c와 key가 같다.</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 마지막 두 원소]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EB%A7%88%EC%A7%80%EB%A7%89-%EB%91%90-%EC%9B%90%EC%86%8C</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EB%A7%88%EC%A7%80%EB%A7%89-%EB%91%90-%EC%9B%90%EC%86%8C</guid>
            <pubDate>Sun, 06 Aug 2023 03:08:20 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수 리스트 <code>num_list</code>가 주어질 때, 마지막 원소가 그전 원소보다 크면 마지막 원소에서 그전 원소를 뺀 값을 마지막 원소가 그전 원소보다 크지 않다면 마지막 원소를 두 배한 값을 추가하여 return하도록 solution 함수를 완성해주세요.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>2 ≤ <code>num_list</code>의 길이 ≤ 10</li>
<li>1 ≤ <code>num_list</code>의 원소 ≤ 9</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">num_list</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[2, 1, 6]</td>
<td align="center">[2, 1, 6, 5]</td>
</tr>
<tr>
<td align="center">[5, 2, 1, 7, 5]</td>
<td align="center">[5, 2, 1, 7, 5, 10]</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>마지막 원소인 6이 그전 원소인 1보다 크기 때문에 6 - 1인 5를 추가해 return합니다.</li>
</ul>
<p>입출력 예 #2</p>
<ul>
<li>마지막 원소인 5가 그전 원소인 7보다 크지 않기 때문에 5의 두 배인 10을 추가해 return합니다.</li>
</ul>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(num_list):
    if  num_list[len(num_list)-1] &gt; num_list[len(num_list) - 2]:
        num_list.append(num_list[len(num_list)-1] - num_list[len(num_list)-2])
    else:
        num_list.append(num_list[len(num_list)-1]*2)
    return num_list</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>맨 마지막 값과 마지막에서 두번째 값을 비교한다. len(num_list)-1 식으로 인덱싱한다.</li>
<li>비교했을 때 맨 마지막 값이 크면 .append()를 활용해 마지막값에서 마지막에서 두번째 값을 뺀 것을 추가한다.</li>
<li>마지막값이 작으면 마지막 값에 곱하기 2를 하여 .append()로 추가한다.<blockquote>
<blockquote>
<p>인덱싱을 할때 <code>len(num_list) -1</code>로 했는데 <code>-1</code>로 인덱싱을 해도 동일한 결과가 나온다.</p>
</blockquote>
</blockquote>
</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(l):
    l.append(l[-1]-l[-2] if l[-1]&gt;l[-2] else l[-1]*2)
    return l</code></pre>
<ul>
<li>append()안에 들어있는 내용을 먼저 확인해보자
l[-1]-l[-2]을 if l[-1]이 l[-2]보다 크면 넣고, 아니면 l[-1]*2를 넣는다.</li>
<li><em>인덱싱에서 -1은 맨 마지막 값, -2는 뒤에서 그다음값으로 뒤에서 부터 인덱싱하는데 사용한다.*</em></li>
<li>l.append()로 l리스트의 맨 마지막에 추가한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 이어 붙인 수]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%9D%B4%EC%96%B4-%EB%B6%99%EC%9D%B8-%EC%88%98</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%9D%B4%EC%96%B4-%EB%B6%99%EC%9D%B8-%EC%88%98</guid>
            <pubDate>Sat, 05 Aug 2023 13:10:26 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수가 담긴 리스트 <code>num_list</code>가 주어집니다. <code>num_list</code>의 홀수만 순서대로 이어 붙인 수와 짝수만 순서대로 이어 붙인 수의 합을 return하도록 solution 함수를 완성해주세요.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>2 ≤ <code>num_list</code>의 길이 ≤ 10</li>
<li>1 ≤ <code>num_list</code>의 원소 ≤ 9</li>
<li><code>num_list</code>에는 적어도 한 개씩의 짝수와 홀수가 있습니다.</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">num_list</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[3, 4, 5, 2, 1]</td>
<td align="center">393</td>
</tr>
<tr>
<td align="center">[5, 7, 8, 3]</td>
<td align="center">581</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>홀수만 이어 붙인 수는 351이고 짝수만 이어 붙인 수는 42입니다. 두 수의 합은 393입니다.</li>
</ul>
<p>입출력 예 #2</p>
<ul>
<li>홀수만 이어 붙인 수는 573이고 짝수만 이어 붙인 수는 8입니다. 두 수의 합은 581입니다.</li>
</ul>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(num_list):
    odd = &quot;&quot;
    even = &quot;&quot;
    for i in range(len(num_list)):
        if num_list[i] % 2 == 0:
            even = even + str(num_list[i])
        else:
            odd = odd + str(num_list[i])
    answer = int(even) + int(odd)
    return answer</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>홀수와 짝수를 각각 담을 빈 문자열을 만든다.</li>
<li>for문을 돌면서 홀수인지 짝수인지 판단한 다음 문자열로 더해 각 변수에 추가한다.</li>
<li>for문을 모두 돌고난 후 odd, even의 문자열을 int로 변환하고 더해 return한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(num_list):
    answer = 0
    a=&quot;&quot;#홀수
    b=&quot;&quot;#짝수
    for i in num_list:
        if i%2!=0:
            a+=str(i)
        else:
            b+=str(i)
    return int(a)+int(b)</code></pre>
<ul>
<li>홀수와 짝수를 각각 담을 빈 문자열을 만든다.</li>
<li>for문을 돌면서 홀수인지 짝수인지 판단한 다음 문자열로 더해 각 변수에 추가한다.</li>
<li>for문을 모두 돌고난 후 odd, even의 문자열을 int로 변환하고 더해 return한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 원소들의 곱과 합]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%9B%90%EC%86%8C%EB%93%A4%EC%9D%98-%EA%B3%B1%EA%B3%BC-%ED%95%A9</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%9B%90%EC%86%8C%EB%93%A4%EC%9D%98-%EA%B3%B1%EA%B3%BC-%ED%95%A9</guid>
            <pubDate>Sat, 05 Aug 2023 12:37:35 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>정수가 담긴 리스트 <code>num_list</code>가 주어질 때, 모든 원소들의 곱이 모든 원소들의 합의 제곱보다 작으면 1을 크면 0을 return하도록 solution 함수를 완성해주세요.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>2 ≤ <code>um_list</code> 길이 ≤ 10</li>
<li>1 ≤ <code>um_list</code> 원소 ≤ 9</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">num_list</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">[3, 4, 5, 2, 1]</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">[5, 7, 8, 3]</td>
<td align="center">0</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>모든 원소의 곱은 120, 합의 제곱은 225이므로 1을 return합니다.</li>
</ul>
<p>입출력 예 #2</p>
<ul>
<li>모든 원소의 곱은 840, 합의 제곱은 529이므로 0을 return합니다.</li>
</ul>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(num_list):
    mul = 1
    sum1 = 0
    for i in range(len(num_list)):
        mul *= num_list[i]
        sum1 += num_list[i]
        print(mul, sum1)
    if mul &gt; sum1**2:
        answer = 0
    else:
        answer = 1
    return answer</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>mul = 1, sum = 0으로 초기화, 곱할때는 1이 초기값이어야하고, 더할때는 0이 초기값이어야한다.</li>
<li>num_list의 길이만큼 for문을 돈다.</li>
<li>for문을 돌면서 곱하기와 더하기를 각각 한다.</li>
<li>for문을 빠져나와 곱셈을 한 것이 더 많은지 덧셈에 제곱이 더 큰지 if문으로 판단한다.</li>
<li>mul이 더 크면 0을 아니면 1을 return한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<ol>
<li><pre><code class="language-python">def solution(num_list):
 s=sum(num_list)**2
 m=eval(&#39;*&#39;.join([str(n) for n in num_list]))
 return 1 if s&gt;m else 0</code></pre>
</li>
</ol>
<ul>
<li>sum()함수를 사용하여 num_list에 있는 값들을 모두 더하고 제곱을 한다.</li>
<li>eval()함수를 사용하여 곱하기를 한다.</li>
<li>eval()안에 식을 문자열로 넣기 위해 &#39;*&#39;.join()으로 num_list 값 사이에 *을 넣는다.</li>
<li>s가 m보다 크면 1을 아니면 0을 return한다.</li>
</ul>
<p>2.</p>
<pre><code class="language-python">def solution(num_list):
    mul = 1 
    for n in num_list:
        mul *= n
    return int(mul &lt; sum(num_list) ** 2)</code></pre>
<ul>
<li>mul 을 1로 초기화한다.</li>
<li>for 문을 돌며 mul에 num_list에 있는 값을 하나씩 곱한다.</li>
<li>mul보다 sum(num_list) ** 2가 크면 True 아니면 False</li>
<li>int()로 변환하여 True는 1로 False는 0으로 반환된다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 주사위 게임2]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%A3%BC%EC%82%AC%EC%9C%84-%EA%B2%8C%EC%9E%842</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EC%A3%BC%EC%82%AC%EC%9C%84-%EA%B2%8C%EC%9E%842</guid>
            <pubDate>Fri, 04 Aug 2023 05:38:57 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>1부터 6까지 숫자가 적힌 주사위가 세 개 있습니다. 세 주사위를 굴렸을 때 나온 숫자를 각각 <code>a</code>, <code>b</code>, <code>c</code>라고 했을 때 얻는 점수는 다음과 같습니다.</p>
<ul>
<li>세 숫자가 모두 다르다면 <code>a</code> + <code>b</code> + <code>c</code> 점을 얻습니다.</li>
<li>세 숫자 중 어느 두 숫자는 같고 나머지 다른 숫자는 다르다면 (<code>a</code> + <code>b</code> + <code>c</code>) × (<code>a</code>^2 + <code>b</code>^2 + <code>c</code>^2 )점을 얻습니다.</li>
<li>세 숫자가 모두 같다면 (<code>a</code> + <code>b</code> + <code>c</code>) × (<code>a</code>^2 + <code>b</code>^2 + <code>c</code>^2 ) × (<code>a</code>^3 + <code>b</code>^3 + <code>c</code>^3 )점을 얻습니다.
세 정수 <code>a</code>, <code>b</code>, <code>c</code>가 매개변수로 주어질 때, 얻는 점수를 return 하는 solution 함수를 작성해 주세요.</li>
</ul>
<h1 id="제한사항">제한사항</h1>
<ul>
<li><code>a</code>, <code>b</code>, <code>c</code>는 1이상 6이하의 정수입니다.</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">a</th>
<th align="center">b</th>
<th align="center">c</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">2</td>
<td align="center">6</td>
<td align="center">1</td>
<td align="center">9</td>
</tr>
<tr>
<td align="center">5</td>
<td align="center">3</td>
<td align="center">3</td>
<td align="center">473</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">4</td>
<td align="center">4</td>
<td align="center">110592</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>예제 1번에서 세 주사위 숫자가 모두 다르므로 2 + 6 + 1 = 9점을 얻습니다. 따라서 9를 return 합니다.</li>
</ul>
<p>입출력 예 #2</p>
<ul>
<li>예제 2번에서 두 주사위 숫자만 같으므로 (5 + 3 + 3) × (52 + 32 + 32 ) = 11 × 43 = 473점을 얻습니다. 따라서 473을 return 합니다.</li>
</ul>
<p>입출력 예 #3</p>
<ul>
<li>예제 3번에서 세 주사위 숫자가 모두 같으므로 (4 + 4 + 4) × (42 + 42 + 42 ) × (43 + 43 + 43 ) = 12 × 48 × 192 = 110,592점을 얻습니다. 따라서 110592를 return 합니다.</li>
</ul>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(a, b, c):
    answer = a + b + c
    if a == b or a == c or b == c:
        answer = answer * (a**2 + b**2 + c**2)
        if a == b and a == c:
            answer = answer * (a**3+b**3+c**3)
    return answer</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>먼저 a, b, c를 더하는 것은 모두 동일하기 때문에 더해서 answer에 넣는다.</li>
<li>if문으로 2개의 숫자가 같은지 확인한다.</li>
<li>2개의 숫자가 같다면 answer에 answer곱하기 (a제곱, b제곱, c제곱을 더한 것)을 한다.</li>
<li>2개가 같은 상태에서 3개가 동일한지 확인한다.</li>
<li>3개가 같다면 앞에 계산한 answer에 각각 3제곱한 것을 곱한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(a, b, c):
    check=len(set([a,b,c]))
    if check==1:
        return 3*a*3*(a**2)*3*(a**3)
    elif check==2:
        return (a+b+c)*(a**2+b**2+c**2)
    else:
        return (a+b+c)</code></pre>
<ul>
<li>set([a,b,c])를 한다.</li>
<li>set()안에 있는 것이 중복이면 하나만 남는다.</li>
<li>그래서 set()을 한 후 len()으로 길이를 구하면 3개 중복일 땐 check = 1, 2개 중복일땐 check = 2, 중복이 없으면 check = 3이 된다.</li>
<li>check값이 1은 3개가 중복이기 때문에 a에 해당하는 것을 3개 곱하고 a를 제곱한 것을 3으로 곱하고, a를 세제곱한 것을 3개 곱하여 모두 곱한다.</li>
<li>check값이 2이면 2개가 중복이므로, <code>(a+b+c) * (a**2 + b**2 + c**2)</code>를 한 것을 return한다.</li>
<li>check값이 3이면 a+b+c를 return한다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[프로그래머스] LV0. 등차수열의 특정한 항만 더하기]]></title>
            <link>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EB%93%B1%EC%B0%A8%EC%88%98%EC%97%B4%EC%9D%98-%ED%8A%B9%EC%A0%95%ED%95%9C-%ED%95%AD%EB%A7%8C-%EB%8D%94%ED%95%98%EA%B8%B0</link>
            <guid>https://velog.io/@yun_in/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LV0.-%EB%93%B1%EC%B0%A8%EC%88%98%EC%97%B4%EC%9D%98-%ED%8A%B9%EC%A0%95%ED%95%9C-%ED%95%AD%EB%A7%8C-%EB%8D%94%ED%95%98%EA%B8%B0</guid>
            <pubDate>Fri, 04 Aug 2023 03:53:27 GMT</pubDate>
            <description><![CDATA[<h1 id="문제-설명">문제 설명</h1>
<p>두 정수 <code>a</code>, <code>d</code>와 길이가 n인 boolean 배열 <code>included</code>가 주어집니다. 첫째항이 <code>a</code>, 공차가 <code>d</code>인 등차수열에서 <code>included[i]</code>가 i + 1항을 의미할 때, 이 등차수열의 1항부터 n항까지 <code>included</code>가 true인 항들만 더한 값을 return 하는 solution 함수를 작성해 주세요.</p>
<h1 id="제한사항">제한사항</h1>
<ul>
<li>1 ≤ <code>a</code> ≤ 100</li>
<li>1 ≤ <code>d</code> ≤ 100</li>
<li>1 ≤ <code>included</code>의 길이 ≤ 100</li>
<li><code>included</code>에는 true가 적어도 하나 존재합니다.</li>
</ul>
<h1 id="입출력-예">입출력 예</h1>
<table>
<thead>
<tr>
<th align="center">a</th>
<th align="center">d</th>
<th align="center">included</th>
<th align="center">result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">3</td>
<td align="center">4</td>
<td align="center">[true, false, false, true, true]</td>
<td align="center">37</td>
</tr>
<tr>
<td align="center">7</td>
<td align="center">1</td>
<td align="center">[false, false, false, true, false, false, false]</td>
<td align="center">10</td>
</tr>
</tbody></table>
<p>입출력 예 설명
입출력 예 #1</p>
<ul>
<li>예제 1번은 <code>a</code>와 <code>d</code>가 각각 3, 4이고 <code>included</code>의 길이가 5입니다. 이를 표로 나타내면 다음과 같습니다.</li>
</ul>
<p>| |1항    |2항    |3항|    4항    |5항|
|:--:|:--:|:--:|:--:|:--:|
|등차수열|    3    |7    |11|    15|    19|
|included    |true    |false    |false    |true    |true|</p>
<p>따라서 true에 해당하는 1항, 4항, 5항을 더한 3 + 15 + 19 = 37을 return 합니다.</p>
<p>입출력 예 #2</p>
<ul>
<li>예제 2번은 <code>a</code>와 <code>d</code>가 각각 7, 1이고 <code>included</code>의 길이가 7입니다. 이를 표로 나타내면 다음과 같습니다.</li>
</ul>
<p>||1항    |2항    |3항|    4항    |5항|    6항|    7항|
|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
|등차수열|    7    |8    |9    |10    |11    |12|    13|
|included|    false|    false|    false|    true|    false|    false|    false|
따라서 4항만 true이므로 10을 return 합니다.</p>
<h1 id="내가-작성한-코드">내가 작성한 코드</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(a, d, included):
    sum = 0
    for i in range(len(included)):
        if included[i] == True:
            sum = sum + a + d*i
    return sum</code></pre>
<p>코드 간단 소개</p>
<ul>
<li>sum = 0으로 선언한다.</li>
<li>for문을 included의 길이만큼 돈다.</li>
<li>included[i]가 True일때 sum + 초기값(a) +  공차(d) * (현재 항 - 1)(i)을 한다.</li>
<li>for문을 모두 돌고 난 후 sum의 값을 return 한다.</li>
</ul>
<h1 id="다른-사람-풀이">다른 사람 풀이</h1>
<blockquote>
</blockquote>
<pre><code class="language-python">def solution(a, d, included):
    answer = 0
    for i in range(len(included)):
        answer += (a + d * i) * int(included[i])
    return answer</code></pre>
<ul>
<li>answer = 0으로 초기화 한다.</li>
<li>for 문을 included의 길이만큼 돈다.</li>
<li>if문을 사용하지 않는다.</li>
<li>대신 (a + d * i)에 int(included[i])를 곱한다.</li>
<li>included[i] 가 True이면 1을, False이면 0이 곱해진다.</li>
<li>for 문을 모두 돌고 난 후 answer값을 return 한다.</li>
</ul>
]]></description>
        </item>
    </channel>
</rss>