<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>comdori-web.log</title>
        <link>https://velog.io/</link>
        <description>(wanna be a) Full-Stack Engineer</description>
        <lastBuildDate>Sun, 04 Apr 2021 12:10:24 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>comdori-web.log</title>
            <url>https://images.velog.io/images/comdori-web/profile/453994a3-0fde-4574-aa16-a8541af612ae/social.jpeg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. comdori-web.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/comdori-web" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[2021.04.04] 코딩테스트 연습]]></title>
            <link>https://velog.io/@comdori-web/2021.04.04-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%97%B0%EC%8A%B5</link>
            <guid>https://velog.io/@comdori-web/2021.04.04-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%97%B0%EC%8A%B5</guid>
            <pubDate>Sun, 04 Apr 2021 12:10:24 GMT</pubDate>
            <description><![CDATA[<p><a href="https://programmers.co.kr/learn/courses/30/lessons/60057">문자열압축</a></p>
<ul>
<li>문제풀이함.<ul>
<li>새로운 문자열을 얻을 때, for문 돌면서 마지막 문자열 처리를 안해줘서 약간 헤멤</li>
<li>로직을 손으로 정확히 안짜봤기 때문에 발생한 문제인것 같기도 함.</li>
</ul>
</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.04.03] 코딩테스트준비]]></title>
            <link>https://velog.io/@comdori-web/2021.04.03-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8%EC%A4%80%EB%B9%84</link>
            <guid>https://velog.io/@comdori-web/2021.04.03-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8%EC%A4%80%EB%B9%84</guid>
            <pubDate>Sat, 03 Apr 2021 14:16:35 GMT</pubDate>
            <description><![CDATA[<p>DFS, BFS 예전에 만들어 놨던 틀보고 다시 한 번 연습해보기.</p>
<pre><code class="language-DFS">#include &lt;vector&gt;
#include &lt;iostream&gt;
#include &lt;queue&gt;

#define MAX_SIZE 10

using namespace std;

vector&lt;vector&lt;int&gt;&gt; maze = {
    {1,0,1,1,1,1},
    {1,0,1,0,1,0},
    {1,0,1,1,1,1},
    {1,1,1,0,1,1},
};

int numOfX = 6;
int numOfY = 4;

pair&lt;int, int&gt; startPos = { 0, 0 };
pair&lt;int, int&gt; endPos = { 5, 3 };

bool isVisit[MAX_SIZE][MAX_SIZE];
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };

vector&lt;pair&lt;int, int&gt;&gt; path;

bool isValidXY(int x, int y)
{
    if ((x &lt; 0) || (y &lt; 0) || (x &gt;= numOfX) || (y &gt;= numOfY))
        return false;
    return true;
}

void dfs(int x, int y)
{
    // 진입시 바로 할 일
    isVisit[x][y] = true;
    path.push_back({x, y});

    // 종료조건 + 종료시 처리할 것 goto
    if ((x == endPos.first) &amp;&amp; (y == endPos.second)) {
        for (int i = 0; i &lt; path.size(); i++) {
            cout &lt;&lt; &quot;[&quot; &lt;&lt;path[i].first &lt;&lt; &quot;,&quot; &lt;&lt; path[i].second &lt;&lt; &quot;]&quot;;
        }
        cout &lt;&lt; endl;
        goto exit;
    }

    // 다음 노드 진입 및 가지치기
    for (int i = 0; i &lt; 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        // vector&lt;vector&lt;int&gt;&gt; 의 경우 x,y가 아닌 y, x 순으로 접근 필요
        if (isValidXY(nx, ny) &amp;&amp; (maze[ny][nx] == 1) &amp;&amp; (isVisit[nx][ny] == false)) {
            dfs(nx, ny);
        }
    }

    // 종료시 처리할  것
exit:
    isVisit[x][y] = false;
    path.pop_back();
}

struct Pos {
    int x, y;
    int level;
};

void bfs(int x, int y)
{
    queue&lt;Pos&gt; q;
    q.push({ x, y, 1});
    // 진입시 바로 할 일
    isVisit[x][y] = true;

    while (!q.empty()) {
        Pos curPos = q.front();
        q.pop();

        // 종료조건
        if ((curPos.x == endPos.first) &amp;&amp; (curPos.y == endPos.second)) {
            cout &lt;&lt; curPos.level &lt;&lt; endl;
            break;
        }

        // 다음 노드 진입 및 가지치기
        for (int i = 0; i &lt; 4; i++) {
            int nx = curPos.x + dx[i];
            int ny = curPos.y + dy[i];
            // vector&lt;vector&lt;int&gt;&gt; 의 경우 x,y가 아닌 y, x 순으로 접근 필요
            if (isValidXY(nx, ny) &amp;&amp; (maze[ny][nx] == 1) &amp;&amp; (isVisit[nx][ny] == false)) {
                q.push({nx, ny, curPos.level + 1});
                // 집입시 바로 할 일
                isVisit[nx][ny] = true;
            }
        }
    }
}

int main()
{
    //dfs(0, 0);
    //bfs(0, 0);
    return 0;
}</code></pre>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

vector&lt;char&gt; elements = { &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39; };
vector&lt;char&gt; path;

void dfs(int preIdx)
{
    // print path
    if (path.size() != 0) { // not include anything yet
        cout &lt;&lt; path.size() &lt;&lt; &quot; : &quot;;
        for (int i = 0; i &lt; path.size(); i++) {
            cout &lt;&lt; path[i] &lt;&lt; &quot; &quot;;
        }
        cout &lt;&lt; endl;
    }

    for (int i = preIdx + 1; i &lt; elements.size(); i++) {
        path.push_back(elements[i]);
        dfs(i);
        path.pop_back();
    }
}

int main()
{
    dfs(-1);
    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.04.02] 정규표현식 추가 정리]]></title>
            <link>https://velog.io/@comdori-web/2021.04.02-%EC%A0%95%EA%B7%9C%ED%91%9C%ED%98%84%EC%8B%9D-%EC%B6%94%EA%B0%80-%EC%A0%95%EB%A6%AC</link>
            <guid>https://velog.io/@comdori-web/2021.04.02-%EC%A0%95%EA%B7%9C%ED%91%9C%ED%98%84%EC%8B%9D-%EC%B6%94%EA%B0%80-%EC%A0%95%EB%A6%AC</guid>
            <pubDate>Fri, 02 Apr 2021 14:22:28 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.youtube.com/watch?v=t3M6toIflyQ&amp;t=167s">관련영상</a>
<a href="https://github.com/dream-ellie/regex">github 링크</a>
<a href="regexr.com/5mhou">연습용사이트</a></p>
<ol>
<li><p>Groups and ranges (그룹과 범위)</p>
<ul>
<li>| : 또는</li>
<li>() : 그룹 - 찾은 것을 그룹별로 알려줌<ul>
<li>(?:) : 찾긴하지만 그룹으로 기억하지는 않음</li>
</ul>
</li>
<li>[] : 문자셋, 괄호안의 어떤 문자든 - (||)과 비슷한 효과<ul>
<li>예) [a-f0-9] : a부터 f까지 혹은 0부터 9까지 찾은</li>
</ul>
</li>
<li>[^] : 제외<pre><code> - 예) [^a-f0-9] : a부터 f까지 혹은 0부터 9까지를 제외하고 찾음</code></pre></li>
</ul>
</li>
<li><p>Quantifiers (수량)</p>
<ul>
<li>? : zero or one</li>
<li><ul>
<li>: zero or more</li>
</ul>
</li>
<li><ul>
<li>: one or more</li>
</ul>
</li>
<li>{n} : n번 반복</li>
<li>{min,} : 최소</li>
<li>{min, max} : 최소, 최대</li>
</ul>
</li>
<li><p>Boundary</p>
<ul>
<li>\b : 단어 경계<ul>
<li>예) <strong>\bYa</strong> 로 찾으면 YaYaYa 중 앞에 있는 <strong>Ya</strong>YaYa로 검색</li>
<li>예) <strong>Ya\b</strong>로 찾으면 YaYaYa 중 뒤에 있는 YaYa<strong>Ya</strong>로 검색<ul>
<li>Ya 하나만을 놓고보면 둘다 경계이기 때문에 <strong>Ya</strong> 검색됨</li>
</ul>
</li>
</ul>
</li>
<li>\B : 단어 경계가 아님<ul>
<li>예) <strong>\BYa</strong> 로 찾으면 YaYaYa 중 Ya<strong>YaYa</strong>로 검색</li>
<li>예) <strong>Ya\B</strong>로 찾으면 YaYaYa 중 뒤에 있는 <strong>YaYa</strong>Ya로 검색<ul>
<li>Ya 하나만을 놓고보면 둘다 경계이기 때문에 검색되지 않음</li>
</ul>
</li>
</ul>
</li>
<li>^ : 문장의 시작<ul>
<li>예) <strong>^Ya</strong>로 찾으면 Ya ya YaYaYa Ya 중 <strong>Ya</strong> ya YaYaYa Ya 로 검색</li>
</ul>
</li>
<li>$ : 문장의 끝 (플래그에 multiline이 안되어 있으면... 전체문장중에만 찾음)<ul>
<li>예) <strong>$Ya</strong>로 찾으면 Ya ya YaYaYa Ya 중 Ya ya YaYaYa <strong>Ya</strong> 로 검색</li>
</ul>
</li>
</ul>
</li>
<li><p>Character classes</p>
<ul>
<li>. : 모든 문자 (새로운줄바꿈 문자 제외)</li>
<li>\ : 특수문자가 아닌 문자<ul>
<li>. : 문자 . 검색</li>
<li>? : 문자 ? 검색</li>
<li>[ : 문자 [ 검색</li>
</ul>
</li>
<li>\d : 숫자(digit)</li>
<li>\D : 숫자가 아닌 모든문자</li>
<li>\w : 숫자를 포함한 모든문자(word) - 특수문자, 공백 제외</li>
<li>\W : 숫자를 포함한 모든문자를 제외한 특수문자, 공백 등</li>
<li>\s : 공백(space)</li>
<li>\S : 공백을 제외한 나머지</li>
</ul>
</li>
</ol>
<h2 id="주의">주의</h2>
<ul>
<li>C++에서 \d를 하니깐... digit 검색이 되지 않았다.. \d를 사용해야한다.</li>
</ul>
<p><a href="http://www.cplusplus.com/reference/regex/ECMAScript/">퍼옴</a></p>
<pre><code>Notice that, in C++, character and string literals also escape characters using the backslash character (\), and this affects the syntax for constructing regular expressions from such types. For example:
1 std::regex e1 (&quot;\\d&quot;);  // regular expression: \d -&gt; matches a digit character
2 std::regex e2 (&quot;\\\\&quot;); // regular expression: \\ -&gt; matches a single backslash (\) character </code></pre><h3 id="c에서-string에서-는-escape-로-사용되기-때문에-를-사용하기-위해서는-로-써야한다">c++에서 string에서 <strong>\</strong>는 escape 로 사용되기 때문에... <strong>\</strong>를 사용하기 위해서는 <strong>\</strong>로 써야한다.</h3>
<ul>
<li>예1) \d : \d : 숫자</li>
<li>예2) \\ : \ : 문자 \</li>
<li>[] 안에서는 특수문자 바꿔줄 필요는 없어보임<ul>
<li>밖에서 \.을 써야 문자 . 을 나타내지만, [.] 문자셋 안에서는 .으로 써도 되는듯</li>
<li>regex reg(&quot;[.]{3}&quot;); 하니까 &quot;...&quot;이 검색됨!</li>
</ul>
</li>
</ul>
<h2 id="연습">연습</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;regex&gt;

using namespace std;

vector&lt;string&gt; getMatches(string str, regex reg)
{
    vector&lt;string&gt; matches;

    // sregex_iterator 내, begin(), end(), reg를 저장하여 순회 가능
    sregex_iterator curMatch(str.begin(), str.end(), reg);
    // lastMatch는 end로 초기화됨
    sregex_iterator lastMatch;

    while (curMatch != lastMatch) {
        smatch match = *curMatch;
        matches.push_back(match.str());
        curMatch++;
    }

    // match.str() // match된 string
    // match.prefix() // match된 string 앞 부분
    // match.suffix() // match된 string 뒷 부분

    return matches;
}

vector&lt;string&gt; getCaptures(string str, regex reg)
{
    vector&lt;string&gt; matches;

    // sregex_iterator 내, begin(), end(), reg를 저장하여 순회 가능
    sregex_iterator curMatch(str.begin(), str.end(), reg);
    // lastMatch는 end로 초기화됨
    sregex_iterator lastMatch;

    while (curMatch != lastMatch) {
        smatch match = *curMatch;
        matches.push_back(match[1]);
        curMatch++;
    }

    // match.str() // match된 string
    // match.prefix() // match된 string 앞 부분
    // match.suffix() // match된 string 뒷 부분

    return matches;
}

int main()
{
    string str = &quot;\
Hi there, Nice to meet you. And Hello there and hi.\n\
I love grey(gray) color not a gry, graayand graaay.grdy\n\
Ya ya YaYaYa Ya\n\
abcdefghijklmnopqrstuvwxyz\n\
ABSCEFGHIJKLMNOPQRSTUVWZYZ\n\
1234567890\n\
.[]{}()\^$|?*+\n\
010-898-0893\n\
010 898 0893\n\
010.898.0893\n\
010-405-3412\n\
02-878-8888\n\
dream.coder.ellie@gmail.com\n\
hel+lo@daum.net\n\
hello@daum.co.kr\n\
...\n\
http://www.youtu.be/-ZClicWm0zM\n\
https://www.youtu.be/-ZClicWm1zM\n\
https://youtu.be/-ZClicWm2zM\n\
youtu.be/-ZClicWm3zM&quot;;

    regex reg1(&quot;\\d{2,3}[- .]\\d{3}[- .]\\d{4}&quot;); // 전화번호 검색
    regex reg2(&quot;[\\w+-._]+@[\\w+-._]+&quot;); // 이메일 검색
    regex reg3(&quot;(?:https?:\\/\\/)?(?:www\\.)?youtu\\.be\/([a-zA-Z0-9-]+)&quot;); // 유튜브에서 ID만 가져오기...

    //vector&lt;string&gt; matches = getMatches(str, reg3);
    vector&lt;string&gt; matches = getCaptures(str, reg3);

    for (int i = 0; i &lt; matches.size(); i++) {
        cout &lt;&lt; i &lt;&lt; &quot; : &quot; &lt;&lt; matches[i] &lt;&lt; endl;
    }
    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[코딩테스트 Cheatsheet]]></title>
            <link>https://velog.io/@comdori-web/%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-Cheatsheet</link>
            <guid>https://velog.io/@comdori-web/%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-Cheatsheet</guid>
            <pubDate>Thu, 01 Apr 2021 12:21:57 GMT</pubDate>
            <description><![CDATA[<h1 id="시험-전-명심할-사항">시험 전, 명심할 사항</h1>
<hr>
<ul>
<li>visual studio 디버깅 모드 한 번 미리 실행할 것! (로딩시간이 걸림)</li>
<li>최적화 문제는 일단 먼저 최적화 없이 구현한 후, 시간될 때 최적화 한다.</li>
<li>정확하게 문제 읽고! 정확하게 이해하고! 알고리즘 정확하게 생각한 뒤! 코드 구현.</li>
<li>큰 흐름부터 먼저 다 짜고, 세부 흐름을 완성시킨다! (복잡할 수록 코드 구현시 효과가 좋음)</li>
<li>조급할 것 없음. 내가 어려우면 남도 어려움.</li>
<li>인덱스를 문제와 일치시키면, 디버깅시 직관적 해석이 가능하니 일치여부 고민필요!</li>
<li>전역변수 초기화 필요한지 체크하기!</li>
</ul>
<h1 id="대략적인-1초-계산방법">대략적인 1초 계산방법</h1>
<hr>
<ul>
<li>O(N) : 1000만</li>
<li>O(NlogN) : 10만</li>
<li>O(N^2) : 2000</li>
<li>O(N^3) : 500</li>
</ul>
<h1 id="자료구조">자료구조</h1>
<hr>
<h2 id="vector">vector</h2>
<ul>
<li>위치 접근 : O(1)</li>
<li>뒤에 원소 추가/제거 : O(1) - push_back, pop_back</li>
<li>임의 위치 원소 추가/제거 : O(N) - insert, erase</li>
<li>꽉 찬 상태에서 원소 추가시, 새로운 공간 할당 및 복사가 이루어짐.</li>
</ul>
<pre><code class="language-cpp">#include &lt;vector&gt;

using namespace std;

int main()
{
    vector&lt;int&gt; vec;

    vec.push_back(10); // 맨 뒤에 10 추가
    vec.pop_back();    // 맨 뒤에 제거
    vec.size(); // 원소 개수
    vec.capacity(); // 여분 포함 - 그때 그때 다름
    vec.insert(vec.begin(), 100); // iter 자리에 100 삽입
    vec.erase(vec.begin());       // iter 자리 삭제
    vec[0]; // index를 통한 접근
    vec.begin(); vec.end(); // 주의 : capacity 만큼 iterator가 동작하므로, size와 다르게 쓰레기값이 있을 수 있음

    return 0;
}</code></pre>
<h2 id="list">list</h2>
<ul>
<li>임의의 위치 추가/제거 : O(1),  위치를 찾는데 O(N)</li>
<li>cache hit율이 떨어짐</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;list&gt;

using namespace std;

int main()
{
    list&lt;int&gt; li;

    li.insert(li.end(), 3); // 마지막 원소 추가
    li.insert(li.begin(), 5); // 처음 원소 추가
    li.remove(3); // 3 원소 제거
    li.erase(li.begin()); // iter를 사용한 삭제

    // iter 접근
    for (list&lt;int&gt;::iterator iter = li.begin(); iter != li.end(); ++iter)
    {
        cout &lt;&lt; *iter &lt;&lt; &quot; - &quot;;
    }
    cout &lt;&lt; endl;

    return 0;
}</code></pre>
<h2 id="deque">deque</h2>
<ul>
<li>vector와 비슷하나 앞, 뒤 추가/삭제 : O(1)</li>
<li>원소들이 메모리상에서 연속적으로 존재하지 않음</li>
<li>꽉 찬 상태에서 원소 추가시, vector와 달리 기존의 원소를 복사하지 않음</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;deque&gt;

using namespace std;

int main()
{
    deque&lt;int&gt; dq;

    dq.push_front(40); // 앞에 원소 추가
    dq.push_back(10); // 뒤에 원소 추가
    dq.front(); // 앞 원소 확인
    dq.back(); // 뒤 원소 확인
    dq.pop_front(); // 앞 원소 제거
    dq.pop_back(); // 뒤 원소 제거

    for (deque&lt;int&gt;::iterator iter = dq.begin(); iter != dq.end(); iter++)
    {
        cout &lt;&lt; *iter &lt;&lt; &quot; - &quot;;
    }
    cout &lt;&lt; endl;

    return 0;
}</code></pre>
<h2 id="map">map</h2>
<ul>
<li>균형 이진 트리 구조</li>
<li>key, value 쌍</li>
<li>key는 고유한 값으로 중복이 불가능함</li>
<li>삽입이 되면서 자동으로 정렬됨 (default는 오름차순)</li>
</ul>
<pre><code class="language-cpp">#include &lt;map&gt;
#include &lt;iostream&gt;

using namespace std;

int main()
{
    map&lt;string, int&gt; m;

    m[&quot;kh&quot;] = 34;
    m[&quot;sm&quot;] = 31;
    m[&quot;bm&quot;] = 32;

    cout &lt;&lt; m[&quot;kh&quot;] &lt;&lt; endl;
    cout &lt;&lt; m[&quot;sm&quot;] &lt;&lt; endl;
    cout &lt;&lt; m[&quot;bm&quot;] &lt;&lt; endl;

    auto it = m.find(&quot;ks&quot;);
    if (it == m.end()) {
        cout &lt;&lt; &quot;Not Exist&quot; &lt;&lt; endl;
    }
    else {
        cout &lt;&lt; &quot;Exist&quot; &lt;&lt; endl;
    }

    return 0;
}</code></pre>
<h2 id="priority_queue-heap">priority_queue, heap</h2>
<pre><code class="language-cpp">#include &lt;queue&gt;
#include &lt;iostream&gt;

using namespace std;

struct Data {
    string name;
    int age;
};

// age 기준 min heap
struct compare {
    bool operator()(Data a, Data b) {
        if (a.age &gt; b.age)
            return true;
        return false;
    }
};

int main()
{
    // min heap
    priority_queue&lt;int, vector&lt;int&gt;, greater&lt;int&gt;&gt; heap;
    // max heap
    //priority_queue&lt;int, vector&lt;int&gt;, less&lt;int&gt;&gt; heap;

    heap.push(3);
    heap.push(1);
    heap.push(2);

    while (heap.empty() == false) {
        int top = heap.top();
        cout &lt;&lt; top &lt;&lt; endl;
        heap.pop();
    }

    // struct, custom heap
    priority_queue&lt;Data, vector&lt;Data&gt;, compare&gt; customHeap;
    customHeap.push({ &quot;kh&quot;, 34 });
    customHeap.push({ &quot;sm&quot;, 31 });
    customHeap.push({ &quot;bm&quot;, 32 });

    while (customHeap.empty() == false) {
        Data top = customHeap.top();
        cout &lt;&lt; top.name &lt;&lt; &quot; : &quot; &lt;&lt; top.age &lt;&lt; endl;
        customHeap.pop();
    }

    return 0;
}</code></pre>
<h1 id="string">string</h1>
<hr>
<h2 id="기본-string-동작">기본 string 동작</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
    string str = &quot;Hello&quot;;
    string str2 = &quot;String2&quot;;
    char arr[20];

    str.push_back(&#39;!&#39;);           // &quot;Hello!&quot;
    str.pop_back();               // &quot;Hello&quot;
    str = str + &quot;!!!&quot;;            // &quot;Hello!!!&quot;
    str[0];                       // &#39;H&#39;
    str.length();                 // 8
    str.c_str();                  // &quot;Hello!!!&quot; // c 스타일의 배열 문자열로 변환
    str.substr(2, 4);             // &quot;ello!&quot; // 2번째 부터 length 4 slice
    str.replace(5, 3, &quot;, World&quot;); // &quot;Hello, World&quot; // 5번째부터 length 2개 제거 후, 내용 삽입
    str.compare(&quot;Hello, World&quot;);  // 같으면 0, ==
    str.find(&quot;Hello&quot;);            // 찾으면 0
    str.copy(arr, 4, 1);          // arr : ello // length 4, index 1 를 arr에 복사
    str.begin();                  // 시작 iterator
    str.end();                    // 끝 iterator (개방)
    swap(str, str2);              // reference 교환 스왑

    // 대문자 변환 , 소문자는 tolower 사용
    for (int i = 0; i &lt; str.length(); i++)
    {
        str[i] = toupper(str[i]);
    }

    return 0;
}</code></pre>
<h2 id="split-string">split string</h2>
<pre><code class="language-cpp">#include &lt;sstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;

using namespace std;

vector&lt;string&gt; split(string input, char delimiter) {
    vector&lt;string&gt; strs;
    stringstream ss(input);
    string line;

    while (getline(ss, line, delimiter)) {
        strs.push_back(line);
    }

    return strs;
}

int main()
{
    string str = &quot;This is example&quot;;
    vector&lt;string&gt; strs = split(str, &#39; &#39;);

    for (int i = 0; i &lt; strs.size(); i++) {
        cout &lt;&lt; strs[i] &lt;&lt; endl;
    }

    return 0;
}</code></pre>
<h2 id="regex-정규표현식">regex, 정규표현식</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;regex&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

vector&lt;string&gt; getMatches(string str, regex reg)
{
    vector&lt;string&gt; matches;

    // sregex_iterator 내, begin(), end(), reg를 저장하여 순회 가능
    sregex_iterator curMatch(str.begin(), str.end(), reg);
    // lastMatch는 end로 초기화됨
    sregex_iterator lastMatch;

    while (curMatch != lastMatch) {
        smatch match = *curMatch;
        matches.push_back(match.str()); 
        curMatch++;
    }

    // match.str() // match된 string
    // match.prefix() // match된 string 앞 부분
    // match.suffix() // match된 string 뒷 부분

    return matches;
}

vector&lt;string&gt; getCaptures(string str, regex reg)
{
    vector&lt;string&gt; matches;

    // sregex_iterator 내, begin(), end(), reg를 저장하여 순회 가능
    sregex_iterator curMatch(str.begin(), str.end(), reg);
    // lastMatch는 end로 초기화됨
    sregex_iterator lastMatch;

    while (curMatch != lastMatch) {
        smatch match = *curMatch;
        matches.push_back(match[1]); // capturing group 1번 사용!
        curMatch++;
    }

    // match.str() // match된 string
    // match.prefix() // match된 string 앞 부분
    // match.suffix() // match된 string 뒷 부분

    return matches;
}

int main()
{
    vector&lt;string&gt; matches;

    string str = &quot;Hi My Name is Hit&quot;;
    regex reg(&quot;Hi[^ ]?&quot;);

    matches = getMatches(str, reg);
    for (int i = 0; i &lt; matches.size(); i++) {
        cout &lt;&lt; matches[i] &lt;&lt; endl;
    }

    // 패턴 검색 후, 검색 내용 중 Capture
    // http://www.youtu.be/-ZClicWm0zM\n\
    // https://www.youtu.be/-ZClicWm1zM\n\
    // https://youtu.be/-ZClicWm2zM\n\
    // youtu.be/-ZClicWm3zM&quot;
    // 위에서 ID만 추출..
    regex reg(&quot;(?:https?:\\/\\/)?(?:www\\.)?youtu\\.be\/([a-zA-Z0-9-]+)&quot;);

    matches = getCaptures(str, reg);
    for (int i = 0; i &lt; matches.size(); i++) {
        cout &lt;&lt; matches[i] &lt;&lt; endl;
    }

    return 0;
}</code></pre>
<h1 id="알고리즘">알고리즘</h1>
<hr>
<h2 id="custom-sort">custom sort</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;

struct Data {
    int x, y;
};

// 1순위 : x 오름차순 정렬, 2순위 y 오름차순 정렬
bool compare(Data a, Data b)
{
    if (a.x &lt; b.x)
        return true;

    if ((a.x == b.x) &amp;&amp; (a.y &lt; b.y))
        return true;

    return false;
}

int main()
{
    vector&lt;Data&gt; vect = { {1, 2}, {2, 3}, {4, 5}, {5, 1}, {3, 4}, {2, 5}, {7, 1}, {7, 2}, {1, 5}};

    sort(vect.begin(), vect.end(), compare);

    cout &lt;&lt; &quot;hello&quot; &lt;&lt; endl;

    return 0;
}</code></pre>
<h2 id="lower_boundupper_bound-이진탐색">lower_bound/upper_bound, 이진탐색</h2>
<ul>
<li>중복되는 것이 없을 땐, lower_bound로 구하고...</li>
<li>중복되는 것이 있을 땐, upper_bound - lower_bound</li>
<li>주의 : upper_bound는 target의 다음 iterator 반환! (개방)</li>
</ul>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int main()
{
    vector&lt;int&gt; uniqueVect = { 2, 4, 3, 1, 5, 9, 8, 7 };
    vector&lt;int&gt; overlapVect = { 2, 4, 3, 1, 4, 9, 4, 3 };

    // 1. 2진 탐색 이전 정렬
    sort(uniqueVect.begin(), uniqueVect.end());
    sort(overlapVect.begin(), overlapVect.end());

    // unique Vect binary search
    int target = 4;
    auto targetIt = lower_bound(uniqueVect.begin(), uniqueVect.end(), target);
    int targetIdx = targetIt - uniqueVect.begin();

    // overlap Vect count
    target = 4;
    auto targetLowerIt = lower_bound(overlapVect.begin(), overlapVect.end(), target); // 4를 가리키는 Iterator 반환
    auto targetUpperIt = upper_bound(overlapVect.begin(), overlapVect.end(), target); // 4가 끝나고 다음 Iterator 반환 (개방)
    int count = targetUpperIt - targetLowerIt;


    return 0;
}</code></pre>
<h2 id="다익스트라">다익스트라</h2>
<ul>
<li>한 노드에서 다른 모든 노드들까지 최단거리를 구함</li>
<li>모든 간선이 자연수여야 함.</li>
<li>그리드 알고리즘, 방문하지 않은 노드 중 최단거리인 노드를 중심으로 최단거리를 업데이트<ul>
<li>방문하지 않은 노드 중 최단거리 == 이미 업데이트가 되지 않는 상태임</li>
</ul>
</li>
</ul>
<pre><code class="language-cpp">#include &lt;queue&gt;
#include &lt;iostream&gt;

using namespace std;

#define NUM_OF_NODE 6

// 1번 노드 부터라고 가정
// 이코테 다익스트라 예제 간선 구현
int costMap[NUM_OF_NODE + 1][NUM_OF_NODE + 1] = {
//   0,1,2,3,4,5,6
    {0,0,0,0,0,0,0}, // 0
    {0,0,2,5,1,0,0}, // 1
    {0,0,0,3,2,0,0}, // 2
    {0,0,3,0,0,0,5}, // 3
    {0,0,0,3,0,1,0}, // 4
    {0,0,0,1,0,0,2}, // 5
    {0,0,0,0,0,0,0}, // 6
};

vector&lt;int&gt; minCosts;
bool isVisit[NUM_OF_NODE];

struct CostInfo {
    int node;
    int cost;
};

struct compare { // for cost min heap
    bool operator()(CostInfo a, CostInfo b) {
        return a.cost &gt; b.cost;
    }
};

void initVars()
{
    minCosts.clear();

    for (int i = 0; i &lt; NUM_OF_NODE; i++)
        isVisit[i] = false;
}

void initMinCosts(int startNode, int numOfNode)
{
    for (int i = 0; i &lt; numOfNode + 1; i++) {
        minCosts.push_back(INT_MAX);
    }
    minCosts[startNode] = 0;
}

void dijkstra(int startNode, int numOfNode)
{
    initVars();

    priority_queue&lt;CostInfo, vector&lt;CostInfo&gt;, compare&gt; heap;
    initMinCosts(startNode, numOfNode);
    heap.push({ startNode, 0 });

    while (heap.empty() == false) {
        CostInfo ci = heap.top();
        heap.pop();

        if (isVisit[ci.node] == true)
            continue;

        isVisit[ci.node] = true;

        for (int target = 1; target &lt;= numOfNode ; target++) {
            if ((costMap[ci.node][target] != 0) &amp;&amp; (isVisit[target] == false)) {
                int curMinCost = minCosts[target];
                int newCost = minCosts[ci.node] + costMap[ci.node][target];

                if (newCost &lt; curMinCost) {
                    minCosts[target] = newCost;
                    heap.push({ target, newCost });
                }
            }
        }
    }
}

int main()
{
    int startNode = 1;
    int numOfNode = 6;
    dijkstra(startNode, numOfNode);

    for (int i = 0; i &lt; minCosts.size(); i++) {
        cout &lt;&lt; minCosts[i] &lt;&lt; endl;
    }

    return 0;
}</code></pre>
<h3 id="기타-최단거리-알고리즘">기타 최단거리 알고리즘</h3>
<ul>
<li>플로이드 워셜 알고리즘<ul>
<li>모든 점에서 min(Pab, Pak + Pkb)를 구해 거리를 업데이트 하는 방식</li>
<li>모든 점간의 최소거리를 구함 (최소 거리 <strong>테이블</strong>이 나옴)</li>
</ul>
</li>
</ul>
<h2 id="dfs-bfs">DFS, BFS</h2>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;iostream&gt;
#include &lt;queue&gt;

#define MAX_SIZE 10

using namespace std;

vector&lt;vector&lt;int&gt;&gt; maze = {
    {1,0,1,1,1,1},
    {1,0,1,0,1,0},
    {1,0,1,1,1,1},
    {1,1,1,0,1,1},
};

int numOfX = 6;
int numOfY = 4;

pair&lt;int, int&gt; startPos = { 0, 0 };
pair&lt;int, int&gt; endPos = { 5, 3 };

bool isVisit[MAX_SIZE][MAX_SIZE];
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };

vector&lt;pair&lt;int, int&gt;&gt; path;

bool isValidXY(int x, int y)
{
    if ((x &lt; 0) || (y &lt; 0) || (x &gt;= numOfX) || (y &gt;= numOfY))
        return false;
    return true;
}

void dfs(int x, int y)
{
    // 진입시 바로 할 일
    isVisit[x][y] = true;
    path.push_back({x, y});

    // 종료조건 + 종료시 처리할 것 goto
    if ((x == endPos.first) &amp;&amp; (y == endPos.second)) {
        for (int i = 0; i &lt; path.size(); i++) {
            cout &lt;&lt; &quot;[&quot; &lt;&lt;path[i].first &lt;&lt; &quot;,&quot; &lt;&lt; path[i].second &lt;&lt; &quot;]&quot;;
        }
        cout &lt;&lt; endl;
        goto exit;
    }

    // 다음 노드 진입 및 가지치기
    for (int i = 0; i &lt; 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        // vector&lt;vector&lt;int&gt;&gt; 의 경우 x,y가 아닌 y, x 순으로 접근 필요
        if (isValidXY(nx, ny) &amp;&amp; (maze[ny][nx] == 1) &amp;&amp; (isVisit[nx][ny] == false)) {
            dfs(nx, ny);
        }
    }

    // 종료시 처리할  것
exit:
    isVisit[x][y] = false;
    path.pop_back();
}

struct Pos {
    int x, y;
    int level;
};

void bfs(int x, int y)
{
    queue&lt;Pos&gt; q;
    q.push({ x, y, 1});
    // 진입시 바로 할 일
    isVisit[x][y] = true;

    while (!q.empty()) {
        Pos curPos = q.front();
        q.pop();

        // 종료조건
        if ((curPos.x == endPos.first) &amp;&amp; (curPos.y == endPos.second)) {
            cout &lt;&lt; curPos.level &lt;&lt; endl;
            break;
        }

        // 다음 노드 진입 및 가지치기
        for (int i = 0; i &lt; 4; i++) {
            int nx = curPos.x + dx[i];
            int ny = curPos.y + dy[i];
            // vector&lt;vector&lt;int&gt;&gt; 의 경우 x,y가 아닌 y, x 순으로 접근 필요
            if (isValidXY(nx, ny) &amp;&amp; (maze[ny][nx] == 1) &amp;&amp; (isVisit[nx][ny] == false)) {
                q.push({nx, ny, curPos.level + 1});
                // 집입시 바로 할 일
                isVisit[nx][ny] = true;
            }
        }
    }
}

int main()
{
    //dfs(0, 0);
    //bfs(0, 0);
    return 0;
}</code></pre>
<h2 id="dfs-조합">DFS 조합</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

vector&lt;char&gt; elements = { &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39; };
vector&lt;char&gt; path;

void dfs(int preIdx)
{
    // print path
    if (path.size() != 0) { // not include anything yet
        cout &lt;&lt; path.size() &lt;&lt; &quot; : &quot;;
        for (int i = 0; i &lt; path.size(); i++) {
            cout &lt;&lt; path[i] &lt;&lt; &quot; &quot;;
        }
        cout &lt;&lt; endl;
    }

    for (int i = preIdx + 1; i &lt; elements.size(); i++) {
        path.push_back(elements[i]);
        dfs(i);
        path.pop_back();
    }
}

int main()
{
    dfs(-1);
    return 0;
}</code></pre>
<h2 id="unionintersection-합집합교집합">union/intersection, 합집합/교집합</h2>
<p>set_union, set_intersection 이전에 반드시 sort 필요함.</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

using namespace std;

vector&lt;string&gt; getUnion(vector&lt;string&gt; &amp;vect1, vector&lt;string&gt; &amp;vect2)
{
    vector&lt;string&gt; buff(vect1.size() + vect2.size());

    sort(vect1.begin(), vect1.end());
    sort(vect2.begin(), vect2.end());

    auto iter = set_union(
        vect1.begin(), vect1.end(),
        vect2.begin(), vect2.end(),
        buff.begin()
    );

    buff.erase(iter, buff.end());

    return buff;
}

vector&lt;string&gt; getIntersection(vector&lt;string&gt;&amp; vect1, vector&lt;string&gt;&amp; vect2)
{
    vector&lt;string&gt; buff(vect1.size() + vect2.size());

    sort(vect1.begin(), vect1.end());
    sort(vect2.begin(), vect2.end());

    auto iter = set_intersection(
        vect1.begin(), vect1.end(),
        vect2.begin(), vect2.end(),
        buff.begin()
    );

    buff.erase(iter, buff.end());

    return buff;
}

int main()
{
    vector&lt;string&gt; vect1 = { &quot;cd&quot;, &quot;ab&quot;, &quot;bc&quot;,};
    vector&lt;string&gt; vect2 = { &quot;cd&quot;, &quot;fg&quot;, &quot;ef&quot;, };

    vector&lt;string&gt; uni = getUnion(vect1, vect2);
    vector&lt;string&gt; inter = getIntersection(vect1, vect2);

    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.04.01] 모의테스트]]></title>
            <link>https://velog.io/@comdori-web/2021.04.01-%EB%AA%A8%EC%9D%98%ED%85%8C%EC%8A%A4%ED%8A%B8</link>
            <guid>https://velog.io/@comdori-web/2021.04.01-%EB%AA%A8%EC%9D%98%ED%85%8C%EC%8A%A4%ED%8A%B8</guid>
            <pubDate>Thu, 01 Apr 2021 08:32:27 GMT</pubDate>
            <description><![CDATA[<p><a href="https://tech.kakao.com/2018/09/21/kakao-blind-recruitment-for2019-round-1/">2019 코딩테스트</a>를 사용하여 모의테스트 해봄. 4.5개 정도 풀었으나... 부족한 점이 보임</p>
<ul>
<li>부족한 점, 알아둬야할 점 정리해서 시험보기 전 보충하기!</li>
</ul>
<p>1번</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;map&gt;
#include &lt;vector&gt;
#include &lt;sstream&gt;

using namespace std;

map&lt;string, string&gt; lastNameMap;

vector&lt;string&gt; split(string input, char delimiter) {
    vector&lt;string&gt; answer;
    stringstream ss(input);
    string temp;

    while (getline(ss, temp, delimiter)) {
        answer.push_back(temp);
    }

    return answer;
}

void initLastNameMap(vector&lt;string&gt;&amp; record)
{
    for (int i = 0; i &lt; record.size(); i++) {
        vector&lt;string&gt; words = split(record[i], &#39; &#39;);
        if ((words[0] == &quot;Enter&quot;) || (words[0] == &quot;Change&quot;)) {
            lastNameMap[words[1]] = words[2];
        }
    }
}
//sdfdfdfssdfsdfsdfdf
string translate(string record)
{
    string result = &quot;&quot;;
    vector&lt;string&gt; words = split(record, &#39; &#39;);
    if (words[0] == &quot;Enter&quot;) {
        result = lastNameMap[words[1]] + &quot;님이 들어왔습니다.&quot;;
    }
    else if (words[0] == &quot;Leave&quot;) {
        result = lastNameMap[words[1]] + &quot;님이 나갔습니다&quot;;
    }
    else {
        // Do nothing
    }
    return result;
}

vector&lt;string&gt; solution(vector&lt;string&gt;&amp; record)
{
    vector&lt;string&gt; answer;

    initLastNameMap(record);

    for (int i = 0; i &lt; record.size(); i++) {
        answer.push_back(translate(record[i]));
    }

    return answer;
}

int main()
{
    vector&lt;string&gt; record = {
        &quot;Enter uid1234 Muzi&quot;,
        &quot;Enter uid4567 Prodo&quot;,
        &quot;Leave uid1234&quot;,
        &quot;Enter uid1234 Prodo&quot;,
        &quot;Change uid4567 Ryan&quot;
    };

    vector&lt;string&gt; result = solution(record);

    cout &lt;&lt; result[0] &lt;&lt; endl;

    return 0;
}</code></pre>
<p>2번</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

struct FailRate {
    int stage;
    double rate;
};

bool compare(FailRate a, FailRate b)
{
    if (a.rate &gt; b.rate)
        return true;

    if (a.rate == b.rate) {
        if (a.stage &lt; b.stage) {
            return true;
        }
    }

    return false;
}

double getRate(int n, int curStage, vector&lt;int&gt;&amp; stages)
{
    int numOfPlayers = 0;
    int numOfFail = 0;

    for (int i = 0; i &lt; stages.size(); i++) {
        if (stages[i] &gt;= curStage) {
            numOfPlayers++;
        }
        if (stages[i] == curStage) {
            numOfFail++;
        }
    }

    if (numOfPlayers == 0)
        return 0;

    return numOfFail / double(numOfPlayers);
}

void calcFailRate(int n, vector&lt;int&gt;&amp; stages, vector&lt;FailRate&gt;&amp; failRates)
{
    for (int stage = 1; stage &lt;= n; stage++) {
        double rate = 0;
        rate = getRate(n, stage, stages);
        failRates.push_back({stage, rate});
    }
}

vector&lt;int&gt; solution(int n, vector&lt;int&gt; stages)
{
    vector&lt;FailRate&gt; failRates;
    vector&lt;int&gt; result;

    calcFailRate(n, stages, failRates);
    sort(failRates.begin(), failRates.end(), compare);

    for (int i = 0; i &lt; failRates.size(); i++) {
        result.push_back(failRates[i].stage);
    }

    return result;
}

int main()
{
    int n = 5;
    vector&lt;int&gt; stages = { 2, 1, 2, 6, 2, 4, 3, 3 };
    vector&lt;int&gt; result = solution(n, stages);

    for (int i = 0; i &lt; result.size(); i++) {
        cout &lt;&lt; result[i] &lt;&lt; endl;
    }

    return 0;
}</code></pre>
<p>3번</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

using namespace std;

vector&lt;int&gt; path;
int numOfRows, numOfCols;

int isUniquePath(vector&lt;vector&lt;string&gt;&gt;&amp; relation, vector&lt;int&gt; &amp;path)
{
    vector&lt;string&gt; keys;

    for (int row = 0; row &lt; numOfRows; row++) {
        vector&lt;string&gt; rowStrs = relation[row];
        string key = &quot;&quot;;
        for (int i = 0; i &lt; path.size(); i++) {
            key += rowStrs[path[i]];
        }
        keys.push_back(key);
    }

    int originSize = keys.size();
    sort(keys.begin(), keys.end());
    keys.erase(unique(keys.begin(), keys.end()), keys.end());
    int uniqueSize = keys.size();

    if (originSize == uniqueSize) {
        return true;
    }

    return false;

}

int dfs(vector&lt;vector&lt;string&gt;&gt;&amp; relation, int preIdx)
{
    if (path.size() != 0) {
        if (isUniquePath(relation, path)) {
            return 1;
        }
    }

    int sum = 0;
    for(int i = preIdx +1 ; i &lt; numOfCols ; i++) {
        path.push_back(i);
        sum += dfs(relation, i);
        path.pop_back();
    }

    return sum;
}

int solution(vector&lt;vector&lt;string&gt;&gt;&amp; relation)
{
    numOfRows = relation.size();
    numOfCols = relation[0].size();

    int answer = dfs(relation, -1);
    cout &lt;&lt; answer &lt;&lt; endl;

    return answer;
}

int main()
{
    vector&lt;vector&lt;string&gt;&gt; relation = {
        {&quot;100&quot;, &quot;ryan&quot;, &quot;music&quot;, &quot;2&quot;},
        {&quot;200&quot;, &quot;apeach&quot;, &quot;math&quot;, &quot;2&quot;},
        {&quot;300&quot;, &quot;tube&quot;, &quot;computer&quot;, &quot;3&quot;},
        {&quot;400&quot;, &quot;con&quot;, &quot;computer&quot;, &quot;4&quot;},
        {&quot;500&quot;, &quot;muzi&quot;, &quot;music&quot;, &quot;3&quot;},
        {&quot;600&quot;, &quot;apeach&quot;, &quot;music&quot;, &quot;2&quot;},
    };

    int answer = solution(relation);

    return 0;
}</code></pre>
<p>4번</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;list&gt;

using namespace std;

struct Food {
    int num;
    int restTime;
};

list&lt;Food&gt; foods;

void initFoods(vector&lt;int&gt; &amp;foodTimes)
{
    for (int i = 0; i &lt; foodTimes.size(); i++) {
        foods.push_back({ i + 1, foodTimes[i] });
    }
}

int eatFoodsUntil(int k)
{
    auto foodIt = foods.begin();
    for (int i = 0; i &lt; k; i++) {
        foodIt-&gt;restTime--;
        if (foodIt-&gt;restTime == 0)
            foodIt = foods.erase(foodIt);
        else
            foodIt++;

        if (foodIt == foods.end()) {
            foodIt = foods.begin();
        }
    }

    return foodIt-&gt;num;
}

int solution(vector&lt;int&gt; foodTimes, int k)
{
    initFoods(foodTimes);
    return eatFoodsUntil(k);
}

int main()
{
    vector&lt;int&gt; foodTimes = { 3, 1, 2 };
    int k = 5;
    int answer = solution(foodTimes, k);

    return 0;
}</code></pre>
<p>5번</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;iostream&gt;
#include &lt;algorithm&gt;

#define MAX_NODES 10001

using namespace std;

struct Node {
    int num;
    int x, y;
    Node* left, * right;
};

Node nodes[MAX_NODES];
int numOfNodes;
Node* root;

void initNodes(vector&lt;pair&lt;int, int&gt;&gt;&amp; nodeinfo)
{
    numOfNodes = nodeinfo.size();

    for (int i = 0; i &lt; numOfNodes; i++) {
        nodes[i].num = i + 1;
        nodes[i].x = nodeinfo[i].first;
        nodes[i].y = nodeinfo[i].second;
        nodes[i].left = NULL;
        nodes[i].right = NULL;
    }
}

bool cmp(Node a, Node b)
{
    return a.x &lt; b.x;
}

void sortNodesByX()
{
    sort(nodes, nodes + numOfNodes, cmp);
}

Node* makeSubTree(Node* arr, int size)
{
    if (size == 0)
        return NULL;

    int maxY = 0;
    int maxYIdx = 0;
    for (int i = 0; i &lt; size; i++) {
        if (arr[i].y &gt; maxY) {
            maxY = arr[i].y;
            maxYIdx = i;
        }
    }

    Node* parent = &amp;arr[maxYIdx];

    parent-&gt;left = makeSubTree(arr, maxYIdx);
    parent-&gt;right = makeSubTree(arr + maxYIdx + 1, size - maxYIdx -1);

    return parent;
}

void dfs(vector&lt;int&gt;&amp; prePath, vector&lt;int&gt;&amp; postPath, Node* node)
{
    if (node == NULL)
        return;

    prePath.push_back(node-&gt;num);
    dfs(prePath, postPath, node-&gt;left);
    dfs(prePath, postPath, node-&gt;right);
    postPath.push_back(node-&gt;num);
}

vector&lt;vector&lt;int&gt;&gt; solution(vector&lt;pair&lt;int, int&gt;&gt;&amp; nodeinfo)
{
    initNodes(nodeinfo);
    sortNodesByX();
    Node *rootNode = makeSubTree(nodes, numOfNodes);

    vector&lt;int&gt; prePath, postPath;
    dfs(prePath, postPath, rootNode);

    return { prePath, postPath };
}

int main()
{
    vector&lt;pair&lt;int, int&gt;&gt; nodeinfo = {
        {5, 3},
        {11, 5},
        {13, 3},
        {3, 5},
        {6, 1},
        {1, 3},
        {8, 6},
        {7, 2},
        {2, 2},
    };

    vector&lt;vector&lt;int&gt;&gt; result = solution(nodeinfo);

    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.31] 코딩테스트 준비]]></title>
            <link>https://velog.io/@comdori-web/2021.03.31-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</link>
            <guid>https://velog.io/@comdori-web/2021.03.31-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</guid>
            <pubDate>Tue, 30 Mar 2021 23:55:50 GMT</pubDate>
            <description><![CDATA[<p>2018 코딩테스트 문제 5번 풀이</p>
<ul>
<li>set_union, set_intersection 이전에 sort 필요함!</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

using namespace std;

void capitalize(string&amp; str)
{
    for (auto&amp; c : str)
        c = toupper(c);
}

bool is_text(char c)
{
    if ((c &gt;= &#39;A&#39;) &amp;&amp; (c &lt;= &#39;Z&#39;))
        return true;
    return false;
}

void getVect(string&amp; str, vector&lt;string&gt; &amp;strVect)
{
    for (int i = 0; i &lt; str.size() - 1; i++) {
        // 둘 다 대문자
        if (is_text(str[i]) &amp;&amp; is_text(str[i+1])) {
            strVect.push_back({ str[i], str[i + 1], &#39;\0&#39; });
        }
    }
}

int getInterSize(vector&lt;string&gt;&amp; str1Vect, vector&lt;string&gt;&amp; str2Vect)
{
    vector&lt;string&gt; buff(str1Vect.size() + str2Vect.size());

    sort(str1Vect.begin(), str1Vect.end());
    sort(str2Vect.begin(), str2Vect.end());

    auto iter = set_intersection(
        str1Vect.begin(), str1Vect.end(),
        str2Vect.begin(), str2Vect.end(),
        buff.begin());
    buff.erase(iter, buff.end());

    return buff.size();
}

int getUniSize(vector&lt;string&gt;&amp; str1Vect, vector&lt;string&gt;&amp; str2Vect)
{
    vector&lt;string&gt; buff(str1Vect.size() + str2Vect.size());

    sort(str1Vect.begin(), str1Vect.end());
    sort(str2Vect.begin(), str2Vect.end());

    auto iter = set_union(str1Vect.begin(), str1Vect.end(),
        str2Vect.begin(), str2Vect.end(), buff.begin());
    buff.erase(iter, buff.end());

    return buff.size();
}

int solution(string str1, string str2)
{
    double answer = 0;

    capitalize(str1);
    capitalize(str2);

    vector&lt;string&gt; str1Vect, str2Vect;

    getVect(str1, str1Vect);
    getVect(str2, str2Vect);

    double interSize = getInterSize(str1Vect, str2Vect);
    double uniSize = getUniSize(str1Vect, str2Vect);

    if ((interSize == 0) &amp;&amp; (uniSize == 0)) {
        answer = 1;
    }
    else {
        answer = interSize / uniSize;
    }

    return int(answer * 65536);
}

int main()
{
    string str1 = &quot;aa1+aa2&quot;;
    string str2 = &quot;AAAA12&quot;;

    int answer = solution(str1, str2);

    cout &lt;&lt; answer &lt;&lt; endl;

    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.30] 코딩테스트 준비]]></title>
            <link>https://velog.io/@comdori-web/2021.03.30-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</link>
            <guid>https://velog.io/@comdori-web/2021.03.30-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</guid>
            <pubDate>Tue, 30 Mar 2021 07:46:49 GMT</pubDate>
            <description><![CDATA[<p>BFS 추가 연습 문제</p>
<p>미로탈출 &amp; 최단거리</p>
<ul>
<li>BFS 이용시 queue에 저장할 때, level을 함께 저장하여 최단거리 알아냄</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;queue&gt;

using namespace std;

struct Point {
    int x, y;
    int level;
};

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool isVisit[7][6];

int solution(int n, int m, int(*map)[6])
{
    queue&lt;Point&gt; q;

    q.push({ 1, 1, 1});
    isVisit[1][1] = true;

    while (q.empty() == false) {
        Point p = q.front();
        q.pop();

        for (int i = 0; i &lt; 4; i++) {
            int nx = p.x + dx[i];
            int ny = p.y + dy[i];
            if ((map[nx][ny] == 1) &amp;&amp; (isVisit[nx][ny] == false)) {
                isVisit[nx][ny] = true;
                q.push({ nx, ny, p.level + 1 });
            }

            if ((nx == n) &amp;&amp; (ny == m))
                return p.level + 1;
        }

    }
}

int main()
{
    int n = 5, m = 4;
    int map[7][6] = {
        {0, 0, 0, 0, 0, 0},
        {0, 1, 1, 1, 0, 0},
        {0, 0, 0, 1, 0, 0},
        {0, 1, 1, 1, 1, 0},
        {0, 1, 0, 0, 1, 0},
        {0, 1, 1, 1, 1, 0},
        {0, 0, 0, 0, 0, 0},
    };

    int answer = solution(n, m, map);

    cout &lt;&lt; answer &lt;&lt; endl;

    return 0;
}</code></pre>
<p>2018 코딩테스트 문제 4 연습</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;list&gt;
#include &lt;stdio.h&gt;

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

int c2i(char c)
{
    return c - &#39;0&#39;;
}

int strToMin(string sTime)
{
    int hour = c2i(sTime[0]) * 10 + c2i(sTime[1]);
    int min = c2i(sTime[3]) * 10 + c2i(sTime[4]);

    return min + (hour * 60);
}

void initMinTimeTable(list&lt;int&gt; &amp;minTimeTable, vector&lt;string&gt;&amp; timetable)
{
    for (int i = 0; i &lt; timetable.size(); i++) {
        minTimeTable.push_back(strToMin(timetable[i]));
    }
}

int getCurTime(int idx, int intervalTime)
{
    int baseHour = 9;
    return (baseHour * 60) + (intervalTime * (idx - 1));
}

bool isPossibleTimeToRide(int min, int curTime)
{
    if (curTime &gt;= min) {
        return true;
    }
    return false;
}

void getOnTheBus(int curTime, int limit, list&lt;int&gt;&amp; minTimeTable)
{
    for (int i = 0; i &lt; limit; i++) {
        if (isPossibleTimeToRide(*minTimeTable.begin(), curTime)) {
            minTimeTable.erase(minTimeTable.begin());
        }
        else {
            break;
        }
    }
}

string minToStr(int min)
{
    int hour = min / 60;
    int minumtes = min % 60;
    char str[20];

    sprintf_s(str, 6, &quot;%02d:%02d&quot;, hour, minumtes);

    string s = str;

    return s;
}

bool cmp(int a, int b)
{
    return a &lt; b;
}

string solution(int n, int t, int m, vector&lt;string&gt;&amp; timetable)
{
    int numOfBus = n;
    int intervalTime = t;
    int maxLimit = m;
    list&lt;int&gt; minTimeTable;
    int answerMin = 0;

    sort(timetable.begin(), timetable.end());
    initMinTimeTable(minTimeTable, timetable);
    //sort(minTimeTable.begin(), minTimeTable.end(), cmp);

    for (int i = 1; i &lt;= numOfBus; i++) {
        int curTime = getCurTime(i, intervalTime);

        if (i == numOfBus) { // last bus
            getOnTheBus(curTime, maxLimit - 1, minTimeTable);
            if (minTimeTable.size() == 0) {
                answerMin = curTime;
                break;
            }

            if (isPossibleTimeToRide(*minTimeTable.begin(), curTime)) {
                answerMin = *minTimeTable.begin() - 1;
                break;
            }
            else {
                answerMin = curTime;
                break;
            }
        }
        else {
            getOnTheBus(curTime, maxLimit, minTimeTable);
        }
    }

    return minToStr(answerMin);
}

int main()
{
    int n = 10;
    int t = 60;
    int m = 45;
    vector&lt;string&gt; timetable = { &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;,
        &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;, &quot;23:59&quot;,
        &quot;23:59&quot;};
    string answer = solution(n, t, m, timetable);

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

    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.29] 코딩테스트 연습]]></title>
            <link>https://velog.io/@comdori-web/2021.03.29-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%97%B0%EC%8A%B5</link>
            <guid>https://velog.io/@comdori-web/2021.03.29-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%97%B0%EC%8A%B5</guid>
            <pubDate>Sun, 28 Mar 2021 23:31:17 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.youtube.com/watch?v=7C9RgOcvkvo&amp;t=2386s">DFS &amp; BFS 강의</a></p>
<ul>
<li>isVisit처리 중요.</li>
<li>DFS 스택을 사용해도 좋지만, 재귀함수를 이용하는 것이 생각이 편함.</li>
<li>BFS는 Queue를 사용해, Queue가 빌때까지 동작...</li>
</ul>
<p>음료수 얼려먹기 문제 풀이</p>
<h2 id="dfs">DFS</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

#define MAX_SIZE 5

int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, -1, 1 };
bool isVisit[MAX_SIZE][MAX_SIZE];
int map[MAX_SIZE][MAX_SIZE] = {
    {1, 1, 1, 1, 1},
    {0, 0, 1, 1, 0},
    {0, 0, 0, 1, 1},
    {1, 1, 1, 1, 1},
    {0, 0, 0, 0, 0},
};

bool isValidXY(int x, int y)
{
    if (x &lt; 0)
        return false;
    if (y &lt; 0)
        return false;
    if (x &gt;= MAX_SIZE)
        return false;
    if (y &gt;= MAX_SIZE)
        return false;

    if (map[x][y] == 1)
        return false;

    return true;
}

void dfs(int x, int y)
{
    isVisit[x][y] = true;
    int nx, ny;

    for (int i = 0; i &lt; 4; i++) {
        nx = x + dx[i];
        ny = y + dy[i];
        if (isValidXY(nx, ny)) {
            if (isVisit[nx][ny] == false) {
                dfs(nx, ny);
            }
        }
    }
}

int main()
{
    int cnt = 0;
    for (int x = 0; x &lt; MAX_SIZE; x++) {
        for (int y = 0; y &lt; MAX_SIZE; y++) {
            if ((isVisit[x][y] == false) &amp;&amp; (map[x][y] == 0)){
                cnt++;
                dfs(x, y);
            }
        }
    }

    cout &lt;&lt; cnt &lt;&lt; endl;

    return 0;
}</code></pre>
<h2 id="bfs">BFS</h2>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;queue&gt;

using namespace std;

#define MAX_SIZE 5

int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, -1, 1 };
bool isVisit[MAX_SIZE][MAX_SIZE];
int map[MAX_SIZE][MAX_SIZE] = {
        {1, 1, 1, 1, 1},
        {0, 0, 1, 1, 0},
        {0, 0, 0, 1, 1},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 0},
};

bool isValidXY(int x, int y)
{
    if (x &lt; 0)
        return false;
    if (y &lt; 0)
        return false;
    if (x &gt;= MAX_SIZE)
        return false;
    if (y &gt;= MAX_SIZE)
        return false;

    if (map[x][y] == 1)
        return false;

    return true;
}

struct Point {
    int x, y;
};

void bfs(int x, int y)
{
    queue&lt;Point&gt; q;

    isVisit[x][y] = true;
    q.push({ x, y });

    while (q.empty() == false) {
        Point p = q.front();
        q.pop();

        int nx, ny;
        for (int i = 0; i &lt; 4; i++) {
            nx = p.x + dx[i];
            ny = p.y + dy[i];
            if (isValidXY(nx, ny)) {
                if (isVisit[nx][ny] == false) {
                    isVisit[nx][ny] = true;
                    q.push({ nx, ny });
                }
            }
        }
    }
}

int main()
{

    int cnt = 0;
    for (int x = 0; x &lt; MAX_SIZE; x++) {
        for (int y = 0; y &lt; MAX_SIZE; y++) {
            if ((isVisit[x][y] == false) &amp;&amp; (map[x][y] == 0)) {
                cnt++;
                bfs(x, y);
            }
        }
    }

    cout &lt;&lt; cnt &lt;&lt; endl;

    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.28] 코딩테스트준비]]></title>
            <link>https://velog.io/@comdori-web/2021.03.28-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8%EC%A4%80%EB%B9%84</link>
            <guid>https://velog.io/@comdori-web/2021.03.28-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8%EC%A4%80%EB%B9%84</guid>
            <pubDate>Sun, 28 Mar 2021 00:02:34 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.youtube.com/watch?v=94RC-DsGMLo&amp;list=PLRx0vPvlEmdAghTr5mXQxGpHjWqSz0dgC&amp;index=5">이진탐색</a></p>
<ul>
<li>파라메트릭 서치 : 최적의 해를 구할 때, 결정문제(예, 아니오)로 바꾸어 해결<ul>
<li>예) 가래떡 문제.. 선형적이 아닌 2진 탐색으로 해결</li>
</ul>
</li>
<li>정렬된 벡터에서 4의 갯수, 5의 갯수를 구할 떄, lower_boud/upper_bound를 확인하여 빼준다.</li>
</ul>
<p>2018 코딩테스트 문제 3</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;list&gt;

using namespace std;

list&lt;string&gt; cache;

int get_data(string city, int cacheSize)
{
    int time;

    auto it = find(cache.begin(), cache.end(), city);
    if (it != cache.end()) { // exist
        time = 1;
        cache.erase(it);
    }
    else {
        time = 5;
    }
    cache.push_back(city);

    if (cache.size() &gt; cacheSize) {
        cache.erase(cache.begin());
    }

    return time;
}

int main()
{
    int cacheSize=2;
    vector&lt;string&gt; cities = {&quot;Jeju&quot;, &quot;Pangyo&quot;, &quot;Seoul&quot;, &quot;NewYork&quot;, &quot;LA&quot;,
        &quot;SanFrancisco&quot;, &quot;Seoul&quot;, &quot;Rome&quot;, &quot;Paris&quot;, &quot;Jeju&quot;, &quot;NewYork&quot;, &quot;Rome&quot;};

    int sum = 0;
    for (int i = 0; i &lt; cities.size(); i++) {
        sum += get_data(cities[i], cacheSize);
    }

    cout &lt;&lt; sum &lt;&lt; endl;

    return 0;
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.26] 코딩테스트 공부]]></title>
            <link>https://velog.io/@comdori-web/2021.03.26-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EA%B3%B5%EB%B6%80</link>
            <guid>https://velog.io/@comdori-web/2021.03.26-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EA%B3%B5%EB%B6%80</guid>
            <pubDate>Fri, 26 Mar 2021 12:46:57 GMT</pubDate>
            <description><![CDATA[<p>문자열 관련 문제를 대비하여 정규표현식 공부함.</p>
<ul>
<li>정규표현식 관련 글 따로 작성함.</li>
</ul>
<p>2018 코딩테스트 문제2번을 풀면서 잘못했던 점은.. 문자열만 자를 생각부터 먼저하다보니 문제를 자세히 보지 않았다... 자세히 봤으면 자르고 시작하는 것이 아니었다..</p>
<h2 id="예제를-보고-내가-문제를-잘-이해했는지-꼭-살펴보자">예제를 보고 내가 문제를 잘 이해했는지 꼭 살펴보자!</h2>
<ul>
<li>너무 복잡하게 생각하지말고 단순하게 풀자!</li>
<li>어차피... 미리 생각 안해놓으면 코드 짜면서 다시 생각해야하니깐... 그리고 생각보다 문제가 복잡하니깐.. 미리 거의 손으로 로직은 짜놓고 코드로 옮기자!</li>
<li>문제 정말 이해 잘하자... 급할 수록 돌아가자...!!</li>
<li>문제 미리 다 짜 놓으면 오히려 빠르다는 사실을 잊지말자!<ul>
<li>오래 끌었던 이유는 문제를 제대로 이해 안해서이다.. 사실 제대로 봤으면 진작에 풀었을 것이다.... 제대로 확인하자!!</li>
</ul>
</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

vector&lt;char&gt; options;
vector&lt;int&gt; scores;

void init_options(string &amp;result)
{
    for (int i = 0; i &lt; 4; i++) {
        options.push_back(&#39;-&#39;);
    }

    int idx = 2;

    for (int i = result.length() - 1 ; i &gt;= 0; i--) {
        if ((result[i] == &#39;*&#39;) || (result[i] == &#39;#&#39;)) {
            options[idx] = result[i];
        }
        if ((result[i] == &#39;S&#39;) || (result[i] == &#39;D&#39;) || (result[i] == &#39;T&#39;)) {
            idx--;
        }
    }
}

bool is_digit(char c)
{
    if ((c &gt;= &#39;0&#39;) &amp;&amp; (c &lt;= &#39;9&#39;))
        return true;

    return false;
}

int get_score(string score, char square)
{
    int iscore = stoi(score);
    if (square == &#39;S&#39;)
        return iscore;
    else if (square == &#39;D&#39;)
        return iscore * iscore;
    else
        return iscore * iscore * iscore;
}

void init_scores(string&amp; result)
{
    int idx = 0;
    string score;
    for (int i = 0; i &lt; result.length(); i++) {
        if (is_digit(result[i])) {
            score.push_back(result[i]);
        }
        if ((result[i] == &#39;S&#39;) || (result[i] == &#39;D&#39;) || (result[i] == &#39;T&#39;)) {
            idx++;
            scores.push_back(get_score(score, result[i]));
            score = &quot;&quot;;
        }
    }
}

int solution(string&amp; result)
{
    init_options(result);
    init_scores(result);

    // calc answer
    int sum = 0;
    for (int i = 0; i &lt; 3; i++) {
        int score = 0;
        switch (options[i]) {
        case &#39;-&#39;:
            score = scores[i];            
            break;
        case &#39;*&#39;:
            score = scores[i] * 2;
            break;
        case &#39;#&#39;:
            score = scores[i] * -1;
            break;
        }

        if (options[i + 1] == &#39;*&#39;)
            score *= 2;

        sum += score;
    }

    return sum;
}

int main()
{
    string result = &quot;1D2S3T*&quot;;
    int answer = solution(result);
    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[regex]]></title>
            <link>https://velog.io/@comdori-web/regex</link>
            <guid>https://velog.io/@comdori-web/regex</guid>
            <pubDate>Fri, 26 Mar 2021 12:34:51 GMT</pubDate>
            <description><![CDATA[<h1 id="정규표현식-일부-요약">정규표현식 일부 요약</h1>
<ol>
<li><p>기본연산자</p>
<ul>
<li><strong>.</strong> : 개행무자를 제외한 모든 문자</li>
<li><strong>a</strong> : 문자 a</li>
<li><strong>ab</strong> : 문자열 ab</li>
<li><strong>x|y</strong> : x나 y</li>
<li><strong>\특수문자</strong> : ^+{}$()[]|-?.* 과 같은 특수문자</li>
</ul>
</li>
<li><p>캐릭터 클래스</p>
<ul>
<li><strong>[a-d]</strong> : a, b, c, d 중 문자 1개</li>
<li><strong>[^a-d]</strong> : a, b, c, d를 제외한 문자 1개</li>
<li><strong>\d</strong> : 숫자(digit) 1개</li>
<li><strong>\D</strong> : 숫자가 아닌 개체 1개</li>
<li><strong>\s</strong> : 공백 1개</li>
<li><strong>\S</strong> : 공백이 아닌 개체 1개</li>
<li><strong>\w</strong> : 알파벳 또는 숫자 1개</li>
<li><strong>\W</strong> : 알파벳이나 숫자가 아닌 개체1개</li>
</ul>
</li>
<li><p>양적 연산자</p>
<ul>
<li><strong>x*</strong> : 0개 이상의 x</li>
<li><strong>x+</strong> : 1개 이상의 x</li>
<li><strong>x?</strong> : 0이나 1개인 x</li>
<li><strong>x{2}</strong> : x가 정확히 2개</li>
<li><strong>x{2,5}</strong> : 2개에서 5개 사이의  x</li>
</ul>
</li>
<li><p>이스케이프 문자</p>
<ul>
<li><strong>\n</strong> : 개행</li>
<li><strong>\r</strong> : 캐리지 리턴(현재 줄의 맨 앞)</li>
<li><strong>\t</strong> : 탭</li>
</ul>
</li>
<li><p>위치 지정</p>
<ul>
<li><strong>^</strong> : 문자열의 처음</li>
<li><strong>\b</strong> : 단어 경계</li>
<li><strong>\B</strong> : 비단어 경계</li>
<li><strong>$</strong> : 문자열의 끝</li>
</ul>
</li>
<li><p>그룹</p>
<ul>
<li><strong>(x)</strong> : 캡처링 그룹</li>
<li><strong>(?:x)</strong> : 비캡처링 그룹</li>
</ul>
</li>
</ol>
<h1 id="regex-사용">regex 사용</h1>
<ul>
<li>std::regex_match(str, re)<ul>
<li>reg 패턴이 전체 str과 매칭여부 true, false 리턴</li>
</ul>
</li>
<li>std::regex_search(str, re)<ul>
<li>reg 패턴이 str내 존재여부 true, false 리턴</li>
</ul>
</li>
<li>std::regex_search(str, smatches, re)<ul>
<li>reg 패턴을 str내에서 찾아 smatches에 담아줌</li>
</ul>
</li>
</ul>
<pre><code class="language-cpp">vector&lt;string&gt; split(string result)
{
    vector&lt;string&gt; results;
    regex reg(&quot;[0-9]*[SDT][*#]*&quot;);

    smatch what;
    for (smatch m; regex_search(result, m, reg); result = m.suffix()) {
        results.push_back(m.str());
    }

    return results;
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.25] 코딩테스트 준비]]></title>
            <link>https://velog.io/@comdori-web/2021.03.25-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</link>
            <guid>https://velog.io/@comdori-web/2021.03.25-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</guid>
            <pubDate>Thu, 25 Mar 2021 12:25:25 GMT</pubDate>
            <description><![CDATA[<p><a href="https://www.youtube.com/watch?v=m-9pAwq1o3w&amp;list=PLRx0vPvlEmdAghTr5mXQxGpHjWqSz0dgC">코딩테스트 경향 분석</a></p>
<ul>
<li>C, C++ 기준 대략적인 1초 계산방법<ul>
<li>O(N) : 1000만</li>
<li>O(NlogN) : 10만</li>
<li>O(N^2) : 2000</li>
<li>O(N^3) : 500</li>
</ul>
</li>
</ul>
<p><a href="https://www.youtube.com/watch?v=2zjoKjt97vQ&amp;list=PLRx0vPvlEmdAghTr5mXQxGpHjWqSz0dgC&amp;index=2">그리드, 구현</a></p>
<p><a href="https://tech.kakao.com/2017/09/27/kakao-blind-recruitment-round-1/">2018 코딩테스트 문제1</a></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

string merge_arr(int a, int b, int n)
{
    int tot = a | b;
    string str;
    for (int i = n -1; i &gt;= 0; i--) {
        char c = (tot &gt;&gt; i) &amp; 1 ? &#39;#&#39; : &#39; &#39;;
        str.push_back(c);
    }
    return str;
}

vector&lt;string&gt; solution(int n, vector&lt;int&gt; arr1, vector&lt;int&gt; arr2)
{
    vector&lt;string&gt; answer;

    for (int i = 0; i &lt; n; i++) {
        answer.push_back(merge_arr(arr1[i], arr2[i], n));
    }

    return answer;
}

int main()
{
    int n = 5;
    vector&lt;int&gt; arr1 = { 9, 20, 28, 18, 11 };
    vector&lt;int&gt; arr2 = { 30, 1, 21, 17, 28 };

    solution(n, arr1, arr2);
    return 0;
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.24] 최단경로알고리즘 학습]]></title>
            <link>https://velog.io/@comdori-web/2021.03.24-%EC%B5%9C%EB%8B%A8%EA%B2%BD%EB%A1%9C%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%ED%95%99%EC%8A%B5</link>
            <guid>https://velog.io/@comdori-web/2021.03.24-%EC%B5%9C%EB%8B%A8%EA%B2%BD%EB%A1%9C%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%ED%95%99%EC%8A%B5</guid>
            <pubDate>Wed, 24 Mar 2021 14:28:42 GMT</pubDate>
            <description><![CDATA[<ol>
<li><p>동영상 학습</p>
<ul>
<li><a href="https://www.youtube.com/watch?v=acqm9mM1P6o&amp;t=886s">최단 경로 알고리즘</a><ul>
<li>다익스트라 알고리즘<ul>
<li>heap에 넣고 빼면서(그 다음 최소를 찾아) 거리를 업데이트 하는 방식</li>
<li>다음 최소를 찾으면 거기는 이미 업데이트가 더이상 되지 않는 상태임 (그리드)</li>
<li>한 점에서 모든 점의 최소거리를 구함</li>
</ul>
</li>
<li>플로이드 워셜 알고리즘<ul>
<li>모든 점에서 min(Pab, Pak + Pkb)를 구해 거리를 업데이트 하는 방식</li>
<li>모든 점간의 최소거리를 구함 (최소 거리 테이블이 나옴)</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>문제풀이</p>
<ul>
<li><a href="https://programmers.co.kr/learn/courses/30/lessons/72413">합승택시요금</a></li>
<li>다익스트라 최단 경로 알고리즘 3회 사용하여 합치는 방법</li>
<li>다익스트라 구현 시 다음 최소 값을 찾을 때 min heap을 사용</li>
</ul>
</li>
<li><p>고칠 점</p>
<ul>
<li>노드는 1부터 시작했는데... 구현할 때는 0부터 시작하는 걸로 하다보니 중간에 꼬였었고.. 꼬인 부분을 그림과 매칭시킬 때 1씩 빼서 생각하는게 생각보단 쉽지 않았다.</li>
<li>가능하다면 인덱스를 일치시키는 것이 좀 더 디버깅에 유리할 듯 하다.</li>
</ul>
</li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.23] 코딩테스트 학습]]></title>
            <link>https://velog.io/@comdori-web/2021.03.23-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%ED%95%99%EC%8A%B5</link>
            <guid>https://velog.io/@comdori-web/2021.03.23-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%ED%95%99%EC%8A%B5</guid>
            <pubDate>Tue, 23 Mar 2021 11:22:21 GMT</pubDate>
            <description><![CDATA[<p>지난 4일동안 집안일로 인해 잠시 학습을 중단했다. 다시 오늘부터 계획을 세우고 진행해야겠다. 일단 지금 시점에서 가장 중요한 것은 코딩 테스트 공부이기 때문에 이를 집중적으로 진행하고, 추가적으로 시간이 될때 부가적인 공부를 해야겠다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.18] 코딩 테스트 준비]]></title>
            <link>https://velog.io/@comdori-web/2021.03.18-%EC%BD%94%EB%94%A9-%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</link>
            <guid>https://velog.io/@comdori-web/2021.03.18-%EC%BD%94%EB%94%A9-%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</guid>
            <pubDate>Thu, 18 Mar 2021 13:13:56 GMT</pubDate>
            <description><![CDATA[<p>오늘은 <a href="https://tech.kakao.com/2021/01/25/2021-kakao-recruitment-round-1/">2021 카카오 신입공채 1차 온라인 코딩테스트</a> 2번문제를 풀어보았다.</p>
<p>일단, 풀어본 느낌으로는 만만치 않다고 생각이 들었으며, 연습이 많이 필요하다고 느꼇다.</p>
<ul>
<li>부족한 점<ul>
<li>문제풀이 방법을 좀 더 생각한 뒤에 코딩을 했으나 모자란 면이 있었음.</li>
<li>문제풀이 방법이 올바른지 실제 예제에 답해보지 않았다가.. 나중에 이해한 내용이 달랐다는 것을 깨달아서 시간이 더 오래걸림!!</li>
<li>5시간동안 7문제 -&gt; 후기 찾아보니 보통 3~4가 커트라인이었다고 함...<ul>
<li>그러니 너무 조급해 하지말고, 문제 이해를 완벽히(예제까지) 확실히 보고 설계하고.. 코딩한다!!</li>
</ul>
</li>
</ul>
</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.17] Go 언어 학습 및 코딩테스트 준비]]></title>
            <link>https://velog.io/@comdori-web/2021.03.17-Go-%EC%96%B8%EC%96%B4-%ED%95%99%EC%8A%B5-%EB%B0%8F-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</link>
            <guid>https://velog.io/@comdori-web/2021.03.17-Go-%EC%96%B8%EC%96%B4-%ED%95%99%EC%8A%B5-%EB%B0%8F-%EC%BD%94%EB%94%A9%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%A4%80%EB%B9%84</guid>
            <pubDate>Wed, 17 Mar 2021 15:16:48 GMT</pubDate>
            <description><![CDATA[<h1 id="go-short-variable-declaration-학습">Go Short Variable Declaration 학습</h1>
<p>-&gt; 기존에 abc, err := somefunc()를 err가 여러번 선언된것 처럼 생각했는데 가능했는지를 이해함.</p>
<h1 id="코딩테스트-준비">코딩테스트 준비</h1>
<p><a href="https://tech.kakao.com/2021/01/25/2021-kakao-recruitment-round-1/">2021 카카오 신입공채 1차 온라인 테스트</a></p>
<ul>
<li>문제 1번 풀이함<ul>
<li>잘 못 했던 부분<ul>
<li>너무 조급하게 코딩하려고 해서 오히려 늦게 코드를 구현함</li>
<li>완전하게 잘 짜려고 하는 욕심을 조금은 버려야 할듯.. (시간 내 문제 풀이를 해야하니.. 만약에 시간내 다 풀었다면 그때 와서 다시 최적화 하자!)<code>코드를 입력하세요</code></li>
</ul>
</li>
</ul>
</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Go Short Variable Declaration]]></title>
            <link>https://velog.io/@comdori-web/Go-Short-Variable-Declaration</link>
            <guid>https://velog.io/@comdori-web/Go-Short-Variable-Declaration</guid>
            <pubDate>Wed, 17 Mar 2021 11:01:03 GMT</pubDate>
            <description><![CDATA[<h3 id="참고자료">참고자료</h3>
<ul>
<li><a href="https://www.geeksforgeeks.org/short-variable-declaration-operator-in-go/">Short Variable Declaration Operator</a></li>
<li>[Difference between var keyword and short declaration operator in Golang]</li>
<li>Discovery Go 도서</li>
</ul>
<h1 id="short-varaible-declaration-operator">Short Varaible Declaration Operator(:=)</h1>
<p>연산자 <strong>:=</strong> 는 var 키워드 및 type을 생략하고 변수를 선언할 때 사용한다. 이 연산자의 주목적은 함수 내의 local 변수의 초기화 및 선언하고 변수의 스코프를 좁히기 위한 것이다. 변수의 타입은 식의 타입(오른쪽에 무엇이 있는가)에 따라 정의된다. 정리하면 go에서는 변수를 생성하는 두 가지 방법이 있다.</p>
<ul>
<li>var 키워드 사용하는 방법</li>
<li>:= 를 사용하는 방법</li>
</ul>
<h2 id="short-variable-operator-사용-방법">Short Variable Operator 사용 방법</h2>
<pre><code class="language-go">변수이름 := 식 또는 값</code></pre>
<p>var 키워드를 사용하면 선언과 초기화를 따로 할 수 있지만, :=를 사용하면 선언과 초기화를 동시에 해야한다. </p>
<p>예제</p>
<pre><code class="language-go">package main

import &quot;fmt&quot;

func main() {
    i := 5
    str := &quot;Hello, World&quot;
    fmt.Println(i)
    fmt.Println(str)
}</code></pre>
<h2 id="short-declaration-operator를-사용하여-여러-개의-변수-선언하기">Short Declaration Operator를 사용하여 여러 개의 변수 선언하기</h2>
<p>Short Declaration Operator를 사용하면 같은 타입 혹은 다른 타입의 변수를 한 번에 여러개 선언할 수 있다.</p>
<p>예제1 :</p>
<pre><code class="language-go">package main

import &quot;fmt&quot;

func main() {
    a, b, c := &quot;Hello&quot;, 5, 2.4
    fmt.Printf(&quot;a : %s, type of a : %T\n&quot;, a, a)
    fmt.Printf(&quot;b : %d, type of b : %T\n&quot;, b, b)
    fmt.Printf(&quot;c : %f, type of c : %T\n&quot;, c, c)
}</code></pre>
<p>결과 :</p>
<pre><code>a : Hello, type of a : string
b : 5, type of b : int
c : 2.400000, type of c : float64</code></pre><p>예제2 :</p>
<pre><code class="language-go">package main

import &quot;fmt&quot;

func main() {
    a, b := 1, 2
    a := 4           // error
    c, b := 3, 4     // Not error
    d, b := 5, &quot;abc&quot; // error

    fmt.Printf(&quot;%d, %T\n&quot;, a, a)
    fmt.Printf(&quot;%d, %T\n&quot;, b, b)
    fmt.Printf(&quot;%d, %T\n&quot;, c, c)
    fmt.Printf(&quot;%d, %T\n&quot;, d, d)
}</code></pre>
<ul>
<li>a := 4 가 에러인 이유는 이미 a가 한 번 선언된 상태이기 때문에 재선언을 할 수 없어서이다.</li>
<li>c, b := 3, 4가 에러가 아닌 이유는 b는 이미 선언되었지만, c는 한 번도 선언되지 않았기 때문에 c는 새로 선언하고, b는 값만 대입된다.</li>
<li>d, b := 5, &quot;abc&quot;가 에러인 이유는 d는 한 번도 선언되지 않았지만, b가 기존에 정수형 타입으로 이미 선언된 상태이기 때문에 타입을 바꿀 수 없어서 이다.</li>
</ul>
<p>여러개의 리턴 값을 가지는 함수에도 := 연산자 사용이 가능하다.</p>
<pre><code class="language-go">package main

import &quot;fmt&quot;

func next(n int) (int, int) {
    return n + 1, n + 2
}

func main() {
    next1, next2 := next(1)
    fmt.Println(next1, next2)
}</code></pre>
<h2 id="지역local-변수--전역global-변수">지역(Local) 변수 / 전역(Global) 변수</h2>
<p>:= 연산자는 block-level scope 를 가지는 지역 변수만 선언 가능하다. 일반적으로 지역 변수는 함수 block 내에서 선언된다. 만약 전역 변수를 :=로 선언하려고 하면 에러가 날 것이다.</p>
<pre><code class="language-go">package main

import &quot;fmt&quot;

a := 3 // error

func main() {
    b := 5 // Not error
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[2021.03.16] 학습기록]]></title>
            <link>https://velog.io/@comdori-web/2021.03.16-%ED%95%99%EC%8A%B5%EA%B8%B0%EB%A1%9D</link>
            <guid>https://velog.io/@comdori-web/2021.03.16-%ED%95%99%EC%8A%B5%EA%B8%B0%EB%A1%9D</guid>
            <pubDate>Tue, 16 Mar 2021 14:58:50 GMT</pubDate>
            <description><![CDATA[<h1 id="go-언어-파고들기">Go 언어 파고들기</h1>
<ul>
<li>Go 자료형 해석</li>
</ul>
<h1 id="코딩테스트-준비">코딩테스트 준비</h1>
<ul>
<li>C++ STL 정리<ul>
<li>string</li>
<li>vector / list /deque</li>
</ul>
</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Visual Studio Tips]]></title>
            <link>https://velog.io/@comdori-web/Visual-Studio-Tips</link>
            <guid>https://velog.io/@comdori-web/Visual-Studio-Tips</guid>
            <pubDate>Tue, 16 Mar 2021 14:18:34 GMT</pubDate>
            <description><![CDATA[<h1 id="inputoutput-파일-설정">input/output 파일 설정</h1>
<ul>
<li>리소스 파일 : input.txt, output.txt 생성</li>
<li>프로젝트&gt;속성&gt;구성 속성&gt;디버깅&gt;명령인수에 아래 내용 입력</li>
</ul>
<pre><code>&lt;input.txt &gt;output.txt</code></pre><h1 id="단축키">단축키</h1>
]]></description>
        </item>
        <item>
            <title><![CDATA[[C++ STL] vector / list / deque]]></title>
            <link>https://velog.io/@comdori-web/C-STL-vector</link>
            <guid>https://velog.io/@comdori-web/C-STL-vector</guid>
            <pubDate>Tue, 16 Mar 2021 13:04:03 GMT</pubDate>
            <description><![CDATA[<h1 id="vector">vector</h1>
<ul>
<li>위치 접근 : O(1)</li>
<li>위치 접근 : O(1)</li>
<li>뒤에 원소 추가 제거 : amortized O(1) - push_back, pop_back</li>
<li>임의의 위치 원소 추가 및 제거 : O(n) - insert, erase</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

int main()
{
    vector&lt;int&gt; vec;

    vec.push_back(10); // 맨 뒤에 10 추가
    vec.push_back(20); // 맨 뒤에 20 추가
    vec.push_back(30); // 맨 뒤에 30 추가
    vec.push_back(40); // 맨 뒤에 40 추가
    vec.pop_back();    // 맨 뒤에 제거

    cout &lt;&lt; vec.size() &lt;&lt; endl;     // 3 : 원소 개수
    cout &lt;&lt; vec.capacity() &lt;&lt; endl; // 4 : 전체 사이즈, 여분 포함 - 그때 그때 다름

    vec.insert(vec.begin(), 100); // iter 자리에 100 삽입
    vec.erase(--vec.end());       // iter 자리 삭제

    // []를 통한 접근
    for (int i = 0; i &lt; vec.size(); i++)
    {
        cout &lt;&lt; vec[i] &lt;&lt; &quot;,&quot;;
    }
    cout &lt;&lt; endl;

    // iterator를 통한 접근 - capacity 만큼 됨...
    for (vector&lt;int&gt;::iterator iter = vec.begin(); iter != vec.end(); ++iter)
    {
        cout &lt;&lt; *iter &lt;&lt; &quot;,&quot;;
    }
    cout &lt;&lt; endl;

    return 0;
}</code></pre>
<h1 id="list">list</h1>
<ul>
<li>double linked list</li>
<li>임의의 위치 추가, 제거 : O(1) 이나 찾는데 O(n)</li>
<li>cache hit율 떨어짐</li>
<li>정말 필요한가 고민해보고 사용</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;list&gt;

using namespace std;

int main()
{
    list&lt;int&gt; li;

    li.insert(li.end(), 1);
    li.insert(li.end(), 2);
    li.insert(li.end(), 3);
    li.insert(li.end(), 4);
    li.insert(li.end(), 5);

    li.remove(3);         // 3 원소 제거
    li.erase(li.begin()); // iter 삭제

    // iter 접근
    for (list&lt;int&gt;::iterator iter = li.begin(); iter != li.end(); ++iter)
    {
        cout &lt;&lt; *iter &lt;&lt; &quot; - &quot;;
    }
    cout &lt;&lt; endl;

    return 0;
}</code></pre>
<h1 id="deque">deque</h1>
<ul>
<li>vector와 비슷하나 앞, 뒤 추가/삭제 작업이 O(1)</li>
<li>원소들이 메모리상에서 연속적으로 존재하지 않음...</li>
<li>꽉찬 상태에서 추가할 때, vector는 새로운 공간 할당 및 복사가 이루어짐.</li>
<li>deque는 기존의 원소를 복사할 필요가 없음</li>
</ul>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;deque&gt;

using namespace std;

int main()
{
    deque&lt;int&gt; dq;

    dq.push_back(10);
    dq.push_back(20);
    dq.push_back(30);
    dq.push_front(40);
    dq.push_front(50);
    dq.push_front(60);

    dq.pop_front();
    dq.pop_back();

    for (deque&lt;int&gt;::iterator iter = dq.begin(); iter != dq.end(); iter++)
    {
        cout &lt;&lt; *iter &lt;&lt; &quot; - &quot;;
    }
    cout &lt;&lt; endl;

    return 0;
}</code></pre>
]]></description>
        </item>
    </channel>
</rss>