<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Ryulurala's notepad</title>
    <link>https://ryulurala.tistory.com/</link>
    <description>개발, 디자인 블로그</description>
    <language>ko</language>
    <pubDate>Mon, 13 Apr 2026 16:45:02 +0900</pubDate>
    <generator>TISTORY</generator>
    <ttl>100</ttl>
    <managingEditor>률무차</managingEditor>
    <image>
      <title>Ryulurala's notepad</title>
      <url>https://tistory1.daumcdn.net/tistory/4020828/attach/01ac6aa041a948d78466c40ffa2cb8ec</url>
      <link>https://ryulurala.tistory.com</link>
    </image>
    <item>
      <title>[프로그래머스] 행렬 테두리 회전하기</title>
      <link>https://ryulurala.tistory.com/358</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;행렬 테두리 회전하기&amp;quot;&lt;br&gt;category: 프로그래머스[Level-2]&lt;br&gt;tags: [C++, JavaScript, 프로그래머스]&lt;br&gt;date: &amp;quot;2021-06-12&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://programmers.co.kr/learn/courses/30/lessons/77485&quot;&gt;행렬 테두리 회전하기&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;C++&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;algorithm&amp;gt;

using namespace std;

int rotate(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; board, int sr, int sc, int er, int ec){
    vector&amp;lt;int&amp;gt; nums;
    nums.push_back(board[sr][sc]);

    int cursor = 0;

    // 우 방향 이동
    for(int x=sc+1; x&amp;lt;=ec; x++){
        int num = board[sr][x];
        nums.push_back(num);

        board[sr][x] = nums[cursor++];
    }

    // 하 방향 이동
    for(int y=sr+1; y&amp;lt;=er; y++){
        int num = board[y][ec];
        nums.push_back(num);

        board[y][ec] = nums[cursor++];
    }

    // 좌 방향 이동
    for(int x=ec-1; x&amp;gt;=sc; x--){
        int num = board[er][x];
        nums.push_back(num);

        board[er][x] = nums[cursor++];
    }

    // 상 방향 이동
    for(int y=er-1; y&amp;gt;=sr; y--){
        int num = board[y][sc];
        nums.push_back(num);

        board[y][sc] = nums[cursor++];
    }

    return *min_element(nums.begin(), nums.end());
}

vector&amp;lt;int&amp;gt; solution(int rows, int columns, vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; queries) {
    vector&amp;lt;int&amp;gt; answer;

    vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; board(rows, vector&amp;lt;int&amp;gt;(columns, 0));

    int count=1;
    for(auto&amp;amp; vec: board){
        for(int&amp;amp; ref: vec){
            ref = count++;
        }
    }

    for(auto vec: queries){
        int startRow = vec[0]-1;
        int startCol = vec[1]-1;
        int endRow = vec[2]-1;
        int endCol = vec[3]-1;

        int minNum = rotate(board, startRow, startCol, endRow, endCol);

        answer.push_back(minNum);
    }


    return answer;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;JavaScript&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;function solution(rows, columns, queries) {
  var answer = [];

  // 회전 함수
  const rotate = (board, startY, startX, endY, endX) =&amp;gt; {
    const nums = [];
    nums.push(board[startY][startX]);

    // 우 방향 이동
    for (let x = startX + 1; x &amp;lt;= endX; x++) {
      const num = board[startY][x];
      nums.push(num);

      board[startY][x] = nums[nums.length - 2];
    }

    // 하 방향 이동
    for (let y = startY + 1; y &amp;lt;= endY; y++) {
      const num = board[y][endX];
      nums.push(num);

      board[y][endX] = nums[nums.length - 2];
    }

    // 좌 방향 이동
    for (let x = endX - 1; x &amp;gt;= startX; x--) {
      const num = board[endY][x];
      nums.push(num);

      board[endY][x] = nums[nums.length - 2];
    }

    // 상 방향 이동
    for (let y = endY - 1; y &amp;gt;= startY; y--) {
      const num = board[y][startX];
      nums.push(num);

      board[y][startX] = nums[nums.length - 2];
    }

    return Math.min(...nums);
  };

  const board = Array.from({ length: rows }, (v, i) =&amp;gt;
    Array.from({ length: columns }, (vv, ii) =&amp;gt; columns * i + ii + 1)
  );

  for (const arr of queries) {
    const [startRow, startCol, endRow, endCol] = arr;

    const minNum = rotate(
      board,
      startRow - 1,
      startCol - 1,
      endRow - 1,
      endCol - 1
    );
    answer.push(minNum);
  }

  return answer;
}&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Programmers Solutions/Level-2</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>프로그래머스</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/358</guid>
      <comments>https://ryulurala.tistory.com/358#entry358comment</comments>
      <pubDate>Sat, 12 Jun 2021 19:50:40 +0900</pubDate>
    </item>
    <item>
      <title>[백준] 정수 삼각형(1932)</title>
      <link>https://ryulurala.tistory.com/357</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;정수 삼각형(1932)&amp;quot;&lt;br&gt;category: 백준[Class-4]&lt;br&gt;tags: [C++, JavaScript, 백준]&lt;br&gt;date: &amp;quot;2021-06-11&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1932&quot;&gt;정수 삼각형(1932)&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;C++&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;algorithm&amp;gt;

using namespace std;

// 문제 풀이
void solution(){
    int n;
    cin &amp;gt;&amp;gt; n;

    // input
    vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; dp;
    for(int i=1; i&amp;lt;=n; i++){
        vector&amp;lt;int&amp;gt; sub(i, 0);

        for(int j=0; j&amp;lt;i; j++){
            cin &amp;gt;&amp;gt; sub[j];
        }

        dp.push_back(sub);
    }

    for(int i=1; i&amp;lt;n; i++){
        dp[i][0] += dp[i-1][0];     // 0번째
        dp[i][i] += dp[i-1][i-1];   // 1번째

        for(int j=1; j&amp;lt;=i-1; j++){
            dp[i][j] += max(dp[i-1][j-1], dp[i-1][j]);
        }
    }

    // print
    cout&amp;lt;&amp;lt;*max_element(dp[n-1].begin(), dp[n-1].end())&amp;lt;&amp;lt;endl;
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, &amp;quot;r&amp;quot;))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    if(exists(&amp;quot;stdin&amp;quot;)){
        freopen(&amp;quot;stdin&amp;quot;, &amp;quot;r&amp;quot;, stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;JavsScript&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);
const input = fs.readFileSync(&amp;quot;dev/stdin&amp;quot;).toString().trim().split(&amp;quot;\n&amp;quot;);

// 문제 풀이
const n = +input[0];

const dp = [];
for (let i = 1; i &amp;lt;= n; i++) {
  input[i] = input[i].split(&amp;quot; &amp;quot;);
  dp.push(input[i].map((v) =&amp;gt; +v));
}

for (let i = 1; i &amp;lt; n; i++) {
  dp[i][0] += dp[i - 1][0]; // 0 번째
  dp[i][i] += dp[i - 1][i - 1]; // n 번째

  for (let j = 1; j &amp;lt; i; j++) {
    dp[i][j] += Math.max(dp[i - 1][j - 1], dp[i - 1][j]);
  }
}

// print
console.log(Math.max(...dp[n - 1]));&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Baekjoon Solutions/Class-4</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>백준</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/357</guid>
      <comments>https://ryulurala.tistory.com/357#entry357comment</comments>
      <pubDate>Fri, 11 Jun 2021 18:08:55 +0900</pubDate>
    </item>
    <item>
      <title>[프로그래머스] 2개 이하로 다른 비트</title>
      <link>https://ryulurala.tistory.com/356</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;2개 이하로 다른 비트&amp;quot;&lt;br&gt;category: 프로그래머스[Level-2]&lt;br&gt;tags: [C++, JavaScript, 프로그래머스]&lt;br&gt;date: &amp;quot;2021-06-11&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://programmers.co.kr/learn/courses/30/lessons/77885&quot;&gt;2개 이하로 다른 비트&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;C++&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;

using namespace std;

vector&amp;lt;long long&amp;gt; solution(vector&amp;lt;long long&amp;gt; numbers) {
    vector&amp;lt;long long&amp;gt; answer;

    for(long long x: numbers){
        // 짝수 or 홀수
        if(x%2==0) {
            answer.push_back(x+1);
        }
        else{
            long long lastZero = (x+1)&amp;amp;(-x);    // 마지막 0 bit 자리
            x |= lastZero;  // 마지막 0을 1로
            x &amp;amp;= ~(lastZero&amp;gt;&amp;gt;1);    // 그 다음 bit를 0으로

            answer.push_back(x);
        }
    }

    return answer;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;JavaScript&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;function solution(numbers) {
  var answer = [];

  numbers.forEach((x) =&amp;gt; {
    x = BigInt(x);

    // x가 짝수 or 홀수
    if (x % 2n === 0n) {
      answer.push(x + 1n); // 마지막 bit만 1로 바꿈
    } else {
      const lastZeroPos = (x + 1n) &amp;amp; -x; // 마지막 0 bit 위치
      x |= lastZeroPos; // 마지막 0 bit 위치: 0 -&amp;gt; 1
      x &amp;amp;= ~(lastZeroPos &amp;gt;&amp;gt; 1n); // 그 다음 위치: 1 -&amp;gt; 0

      answer.push(x);
    }
  });

  return answer;
}&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Programmers Solutions/Level-2</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>프로그래머스</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/356</guid>
      <comments>https://ryulurala.tistory.com/356#entry356comment</comments>
      <pubDate>Fri, 11 Jun 2021 18:08:14 +0900</pubDate>
    </item>
    <item>
      <title>[프로그래머스] 로또의 최고 순위와 최저 순위</title>
      <link>https://ryulurala.tistory.com/355</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;로또의 최고 순위와 최저 순위&amp;quot;&lt;br&gt;category: 프로그래머스[Level-1]&lt;br&gt;tags: [C++, JavaScript, 프로그래머스]&lt;br&gt;date: &amp;quot;2021-06-11&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://programmers.co.kr/learn/courses/30/lessons/77484&quot;&gt;로또의 최고 순위와 최저 순위&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;C++&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;

using namespace std;

vector&amp;lt;int&amp;gt; solution(vector&amp;lt;int&amp;gt; lottos, vector&amp;lt;int&amp;gt; win_nums) {
    vector&amp;lt;int&amp;gt; answer;

    // 낙첨, 낙첨, 5등, 4등, ..., 1등
    int lookup[] = {6, 6, 5, 4, 3, 2 ,1};

    // 낙서한 갯수
    int zeroCount = 0;
    for(int e: lottos){
        if(e == 0) zeroCount++;
    }

    // 맞은 갯수
    int winCount = 0;
    for(int winNum: win_nums){
        for(int have: lottos){
            if(have != winNum) continue;

            winCount++;
            break;
        }
    }

    // 최대, 최소
    answer.push_back(lookup[winCount+zeroCount]);
    answer.push_back(lookup[winCount]);

    return answer;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;JavaScript&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;function solution(lottos, win_nums) {
  var answer = [];

  // 낙첨, 낙첨, 5등, 4등, ..., 1등
  const lookup = [6, 6, 5, 4, 3, 2, 1];

  // 알아볼 수 없는 숫자 갯수
  const zeroCount = lottos.reduce((prev, value) =&amp;gt; {
    if (value === 0) prev++;

    return prev;
  }, 0);

  // 맞춘 갯수
  const winCount = win_nums.reduce((prev, value) =&amp;gt; {
    for (const have of lottos) {
      if (have === value) {
        prev++;
        break;
      }
    }

    return prev;
  }, 0);

  // 최대, 최소
  answer.push(lookup[winCount + zeroCount]);
  answer.push(lookup[winCount]);

  return answer; // 최고 순위, 최저 순위
}&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Programmers Solutions/Level-1</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>프로그래머스</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/355</guid>
      <comments>https://ryulurala.tistory.com/355#entry355comment</comments>
      <pubDate>Fri, 11 Jun 2021 15:40:22 +0900</pubDate>
    </item>
    <item>
      <title>[프로그래머스] 약수의 개수와 덧셈</title>
      <link>https://ryulurala.tistory.com/354</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;약수의 개수와 덧셈&amp;quot;&lt;br&gt;category: 프로그래머스[Level-1]&lt;br&gt;tags: [C++, JavaScript, 프로그래머스]&lt;br&gt;date: &amp;quot;2021-06-11&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://programmers.co.kr/learn/courses/30/lessons/77884&quot;&gt;약수의 개수와 덧셈&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;C++&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;

using namespace std;

int solution(int left, int right) {
    int answer = 0;

    // 1 ~ 1000까지 약수의 개수 구하기
    vector&amp;lt;int&amp;gt; divisor(1001, 0);
    for(int i=1; i&amp;lt;=1000; i++){
        for(int j=1; j&amp;lt;=1000/i; j++){
            divisor[i*j]++;
        }
    }

    for(int i=left; i&amp;lt;=right; i++){
        if(divisor[i]%2==0)
            answer += i;    // 짝수
        else
            answer -= i;    // 홀수
    }

    return answer;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;JavaScript&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;function solution(left, right) {
  var answer = 0;

  // 1 ~ 1000까지 약수의 개수 구하기
  const divisor = Array(1001).fill(0);
  for (let i = 1; i &amp;lt;= 1000; i++) {
    for (let j = 1; j &amp;lt;= Math.floor(1000 / i); j++) {
      divisor[i * j]++;
    }
  }

  for (let i = left; i &amp;lt;= right; i++) {
    if (divisor[i] % 2 === 0) answer += i;
    // 짝수
    else answer -= i; // 홀수
  }

  return answer;
}&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Programmers Solutions/Level-1</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>프로그래머스</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/354</guid>
      <comments>https://ryulurala.tistory.com/354#entry354comment</comments>
      <pubDate>Fri, 11 Jun 2021 15:12:34 +0900</pubDate>
    </item>
    <item>
      <title>[백준] 곱셈(1629)</title>
      <link>https://ryulurala.tistory.com/353</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;곱셈(1629)&amp;quot;&lt;br&gt;category: 백준[Class-4]&lt;br&gt;tags: [C++, JavaScript, 백준]&lt;br&gt;date: &amp;quot;2021-06-10&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1629&quot;&gt;곱셈(1629)&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;C++&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;

using namespace std;

long long pow(int a, int b, int c){
    if(b &amp;gt; 1){
        long long half = pow(a, b/2, c)%c;

        if(b%2==0)
            return half*half%c;     // b가 짝수
        else
            return half*half%c*a%c;   // b가 홀수
    }
    else return a;
}

// 문제 풀이
void solution(){
    int a, b, c;
    cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b &amp;gt;&amp;gt; c;

    cout&amp;lt;&amp;lt;pow(a%c, b, c)&amp;lt;&amp;lt;&amp;quot;\n&amp;quot;;
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, &amp;quot;r&amp;quot;))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    if(exists(&amp;quot;stdin&amp;quot;)){
        freopen(&amp;quot;stdin&amp;quot;, &amp;quot;r&amp;quot;, stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;JavsScript&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);
const input = fs.readFileSync(&amp;quot;dev/stdin&amp;quot;).toString().trim().split(&amp;quot;\n&amp;quot;);

// 함수
const pow = (a, b, c) =&amp;gt; {
  if (b &amp;gt; 1n) {
    const half = pow(a, BigInt(parseInt(b / 2n)), c) % c;

    if (b % 2n === 0n) return (half * half) % c;
    else return (((half * half) % c) * a) % c;
  } else return a % c;
};

// 문제 풀이
const [a, b, c] = input[0].split(&amp;quot; &amp;quot;);

console.log(parseInt(pow(BigInt(+a), BigInt(+b), BigInt(+c))));&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Baekjoon Solutions/Class-4</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>백준</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/353</guid>
      <comments>https://ryulurala.tistory.com/353#entry353comment</comments>
      <pubDate>Thu, 10 Jun 2021 23:42:26 +0900</pubDate>
    </item>
    <item>
      <title>[백준] RGB거리(1149)</title>
      <link>https://ryulurala.tistory.com/352</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;RGB거리(1149)&amp;quot;&lt;br&gt;category: 백준[Class-4]&lt;br&gt;tags: [C++, JavaScript, 백준]&lt;br&gt;date: &amp;quot;2021-06-06&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1149&quot;&gt;RGB거리(1149)&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;C++&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;

using namespace std;

// 문제 풀이
void solution(){
    int n;
    cin &amp;gt;&amp;gt; n;

    vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; dp(n+1, vector&amp;lt;int&amp;gt;(3, 0));
    for(int i=1; i&amp;lt;=n; i++){
        int red, green, blue;
        cin &amp;gt;&amp;gt; red &amp;gt;&amp;gt; green &amp;gt;&amp;gt; blue;

        dp[i][0] = red + min(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = green + min(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = blue + min(dp[i-1][0], dp[i-1][1]);
    }

    cout&amp;lt;&amp;lt;min(dp[n][0], min(dp[n][1], dp[n][2]))&amp;lt;&amp;lt;endl;
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, &amp;quot;r&amp;quot;))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    if(exists(&amp;quot;stdin&amp;quot;)){
        freopen(&amp;quot;stdin&amp;quot;, &amp;quot;r&amp;quot;, stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;JavsScript&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);
const input = fs.readFileSync(&amp;quot;dev/stdin&amp;quot;).toString().trim().split(&amp;quot;\n&amp;quot;);

// 문제 풀이
const n = +input[0];

input[0] = [0, 0, 0];
for (let i = 1; i &amp;lt;= n; i++) {
  input[i] = input[i].split(&amp;quot; &amp;quot;).map((v) =&amp;gt; +v);
  input[i][0] += Math.min(input[i - 1][1], input[i - 1][2]);
  input[i][1] += Math.min(input[i - 1][0], input[i - 1][2]);
  input[i][2] += Math.min(input[i - 1][0], input[i - 1][1]);
}

console.log(Math.min(...input[n]));&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Baekjoon Solutions/Class-4</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>백준</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/352</guid>
      <comments>https://ryulurala.tistory.com/352#entry352comment</comments>
      <pubDate>Sun, 6 Jun 2021 18:31:39 +0900</pubDate>
    </item>
    <item>
      <title>[백준] 트리의 부모 찾기(11725)</title>
      <link>https://ryulurala.tistory.com/351</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;트리의 부모 찾기(11725)&amp;quot;&lt;br&gt;category: 백준[Class-4]&lt;br&gt;tags: [C++, JavaScript, 백준]&lt;br&gt;date: &amp;quot;2021-05-31&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/11725&quot;&gt;트리의 부모 찾기(11725)&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;C++&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;queue&amp;gt;

using namespace std;

// 문제 풀이
void solution(){
    int n;
    cin &amp;gt;&amp;gt; n;

    vector&amp;lt;int&amp;gt; graph[n+1];
    for(int i=0; i&amp;lt;n; i++){
        int v1, v2;
        cin &amp;gt;&amp;gt; v1 &amp;gt;&amp;gt; v2;

        // 연결
        graph[v1].push_back(v2);
        graph[v2].push_back(v1);
    }

    // BFS
    vector&amp;lt;int&amp;gt; parent(n+1, 0);
    queue&amp;lt;int&amp;gt; q;
    q.push(1);
    parent[1] = 1;
    while(!q.empty()){
        int current = q.front();
        q.pop();

        // 연결된 정점들
        for(int v: graph[current]){
            if(parent[v] == 0){
                parent[v] = current;
                q.push(v);
            }
        }
    }

    for(int i=2; i&amp;lt;=n; i++){
        cout&amp;lt;&amp;lt;parent[i]&amp;lt;&amp;lt;&amp;quot;\n&amp;quot;;
    }
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, &amp;quot;r&amp;quot;))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    if(exists(&amp;quot;stdin&amp;quot;)){
        freopen(&amp;quot;stdin&amp;quot;, &amp;quot;r&amp;quot;, stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;JavsScript&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);
const input = fs.readFileSync(&amp;quot;dev/stdin&amp;quot;).toString().trim().split(&amp;quot;\n&amp;quot;);

// 문제 풀이
const n = +input[0];

const graph = Array.from({ length: n + 1 }, () =&amp;gt; []);
for (let i = 1; i &amp;lt; input.length; i++) {
  const [v1, v2] = input[i].split(&amp;quot; &amp;quot;);

  // 연결
  graph[+v1].push(+v2);
  graph[+v2].push(+v1);
}

// BFS
const parent = Array(n + 1).fill(0);
const queue = [];
parent[1] = 1;
queue.push(1);

while (queue.length &amp;gt; 0) {
  const current = queue[0];
  queue.shift(); // pop

  for (const next of graph[current]) {
    if (parent[next] === 0) {
      parent[next] = current;
      queue.push(next);
    }
  }
}

// 2번부터
const log = [];
for (let i = 2; i &amp;lt;= n; i++) {
  log.push(parent[i]);
}

// print
console.log(log.join(&amp;quot;\n&amp;quot;));&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Baekjoon Solutions/Class-4</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>백준</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/351</guid>
      <comments>https://ryulurala.tistory.com/351#entry351comment</comments>
      <pubDate>Mon, 31 May 2021 18:28:01 +0900</pubDate>
    </item>
    <item>
      <title>[백준] 가장 긴 증가하는 부분 수열(11053)</title>
      <link>https://ryulurala.tistory.com/350</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;가장 긴 증가하는 부분 수열(11053)&amp;quot;&lt;br&gt;category: 백준[Class-4]&lt;br&gt;tags: [C++, JavaScript, 백준]&lt;br&gt;date: &amp;quot;2021-05-31&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/11053&quot;&gt;가장 긴 증가하는 부분 수열(11053)&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;C++&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;algorithm&amp;gt;

using namespace std;

// 문제 풀이
void solution(){
    int n;
    cin &amp;gt;&amp;gt; n;

    vector&amp;lt;int&amp;gt; nums;
    nums.push_back(0);
    for(int i=0; i&amp;lt;n; i++){
        int a;
        cin &amp;gt;&amp;gt; a;

        nums.push_back(a);
    }

    vector&amp;lt;int&amp;gt; dp(n+1, 0);     // 부분 수열의 수
    dp[1] = 1;  // 첫 번째
    for(int i=2; i&amp;lt;=n; i++){
        int current = nums[i];
        int max = dp[i];

        for(int j=i-1; j&amp;gt;0; j--){
            if(current &amp;gt; nums[j] &amp;amp;&amp;amp; max &amp;lt; dp[j]){
                max = dp[j];
            }
        }

        dp[i] = max+1;
    }

    // 가장 큰 부분 수열의 수 출력
    cout&amp;lt;&amp;lt;*max_element(dp.begin(), dp.end())&amp;lt;&amp;lt;endl;
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, &amp;quot;r&amp;quot;))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    if(exists(&amp;quot;stdin&amp;quot;)){
        freopen(&amp;quot;stdin&amp;quot;, &amp;quot;r&amp;quot;, stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;JavsScript&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);
const input = fs.readFileSync(&amp;quot;dev/stdin&amp;quot;).toString().trim().split(&amp;quot;\n&amp;quot;);

// 문제 풀이
const n = +input[0];
const nums = input[1].split(&amp;quot; &amp;quot;);

const dp = Array(n).fill(0);
dp[0] = 1;
for (let i = 1; i &amp;lt; n; i++) {
  const current = +nums[i];
  let currentCount = dp[i];

  for (let j = 0; j &amp;lt; i; j++) {
    const prev = +nums[j];
    const prevCount = dp[j];

    if (prev &amp;lt; current &amp;amp;&amp;amp; currentCount &amp;lt; prevCount) {
      currentCount = prevCount;
    }
  }

  dp[i] = currentCount + 1;
}

// 가장 큰 부분 수열 수 출력
console.log(Math.max(...dp));&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Baekjoon Solutions/Class-4</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>백준</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/350</guid>
      <comments>https://ryulurala.tistory.com/350#entry350comment</comments>
      <pubDate>Mon, 31 May 2021 18:27:28 +0900</pubDate>
    </item>
    <item>
      <title>[백준] 스티커(9465)</title>
      <link>https://ryulurala.tistory.com/349</link>
      <description>&lt;hr&gt;
&lt;p&gt;title: &amp;quot;스티커(9465)&amp;quot;&lt;br&gt;category: 백준[Class-4]&lt;br&gt;tags: [C++, JavaScript, 백준]&lt;br&gt;date: &amp;quot;2021-05-29&amp;quot;&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;문제 링크&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/9465&quot;&gt;스티커(9465)&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;C++&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;

using namespace std;

// 문제 풀이
void solution(){
    int t;
    cin &amp;gt;&amp;gt; t;

    for(int i=0; i&amp;lt;t; i++){
        int n;
        cin &amp;gt;&amp;gt; n;

        // Init
        vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; stickers;
        for(int j=0; j&amp;lt;2; j++){
            vector&amp;lt;int&amp;gt; vec;

            vec.push_back(0);   // 0번 째 추가
            for(int k=0; k&amp;lt;n; k++){
                int x;
                cin &amp;gt;&amp;gt; x;

                vec.push_back(x);
            }

            stickers.push_back(vec);
        }

        // DP
        if(n==1){
            cout&amp;lt;&amp;lt;max(stickers[0][1], stickers[1][1])&amp;lt;&amp;lt;&amp;quot;\n&amp;quot;;
        }
        else {
            for(int k=2; k&amp;lt;=n; k++){
                // 0행 k열 뽑을 경우, 1행 k-1열과 1행 k-2열 중 큰 값과 0행 k열 뽑을 경우를 더함.
                stickers[0][k] = max(stickers[1][k-1], stickers[1][k-2]) + stickers[0][k];
                // 1행 k열 뽑을 경우, 0행 k-1열과 0행 k-2열 중 큰 값과 1행 k열 뽑을 경우를 더함.
                stickers[1][k] = max(stickers[0][k-1], stickers[0][k-2]) + stickers[1][k];
            }

            cout&amp;lt;&amp;lt;max(stickers[0][n], stickers[1][n])&amp;lt;&amp;lt;&amp;quot;\n&amp;quot;;
        }
    }
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, &amp;quot;r&amp;quot;))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    if(exists(&amp;quot;stdin&amp;quot;)){
        freopen(&amp;quot;stdin&amp;quot;, &amp;quot;r&amp;quot;, stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;JavsScript&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);
const input = fs.readFileSync(&amp;quot;dev/stdin&amp;quot;).toString().trim().split(&amp;quot;\n&amp;quot;);

// Function

// 문제 풀이
let cursor = 0;
const t = +input[cursor++];

for (let i = 0; i &amp;lt; t; i++) {
  const n = +input[cursor++];
  const stickers = [];
  stickers.push(input[cursor++].split(&amp;quot; &amp;quot;));
  stickers.push(input[cursor++].split(&amp;quot; &amp;quot;));
  stickers[0].unshift(0);
  stickers[1].unshift(0);

  if (n &amp;gt;= 2) {
    // string -&amp;gt; int
    stickers[0][1] = +stickers[0][1];
    stickers[1][1] = +stickers[1][1];

    for (let k = 2; k &amp;lt;= n; k++) {
      // string -&amp;gt; int
      stickers[0][k] = +stickers[0][k];
      stickers[1][k] = +stickers[1][k];

      // dp
      stickers[0][k] += Math.max(stickers[1][k - 1], stickers[1][k - 2]);
      stickers[1][k] += Math.max(+stickers[0][k - 1], +stickers[0][k - 2]);
    }
  }

  console.log(Math.max(stickers[0][n], stickers[1][n]));
}&lt;/code&gt;&lt;/pre&gt;</description>
      <category>Baekjoon Solutions/Class-4</category>
      <category>C++</category>
      <category>JavaScript</category>
      <category>백준</category>
      <author>률무차</author>
      <guid isPermaLink="true">https://ryulurala.tistory.com/349</guid>
      <comments>https://ryulurala.tistory.com/349#entry349comment</comments>
      <pubDate>Sat, 29 May 2021 21:53:55 +0900</pubDate>
    </item>
  </channel>
</rss>