Notice
Recent Posts
Recent Comments
Today
Total
01-26 01:17
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[2018 KAKAO BLIND RECRUITMENT] (1์ฐจ) ๋น„๋ฐ€์ง€๋„ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[2018 KAKAO BLIND RECRUITMENT] (1์ฐจ) ๋น„๋ฐ€์ง€๋„

WonderJay 2022. 7. 5. 17:25
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/17681

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

bitset ์„ ์ด์šฉํ•ด์„œ ๋น„ํŠธ ์—ฐ์‚ฐ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๋‹ค.

 

1. ํ•œ ์ค„์”ฉ ์ฃผ์–ด์ง€๋Š” ์ง€๋„1, ์ง€๋„2 ๋ฅผ bitset ์— ๋„ฃ์€ ๋‹ค์Œ OR ์—ฐ์‚ฐ์„ ์ทจํ•œ๋‹ค.

2. ๊ทธ ๊ฒฐ๊ณผ๋ฅผ string ์œผ๋กœ ๋ณ€ํ™˜ํ•œ ๋’ค, substr ์„ ์ด์šฉํ•˜์—ฌ ์ง€๋„์˜ ๊ฐ€๋กœ ์„ธ๋กœ ํฌ๊ธฐ์— ๋งž์ถ”์–ด ์ถ”์ถœํ•œ๋‹ค.

3. ํ•ด๋‹น ๋ฌธ์ž์—ด์„ ์ˆœํšŒํ•˜๋ฉฐ 1 ์ด๋ฉด ์ž„์‹œ ๋ฌธ์ž์—ด decoded ์— # ์„,  0์ด๋ฉด 0 ์„ append ํ•œ๋‹ค.

4. appending ์ด ๋๋‚˜๋ฉด answer ์— push_back ํ•˜๋Š” ๊ฒƒ์„ ๋ฐ˜๋ณตํ•œ๋‹ค.

 

[C++]

#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)

using namespace std;

vector<string> solution(int n, vector<int> arr1, vector<int> arr2) {
    vector<string> answer;
    fastio;

    bitset<16> bit_map_1st;
    bitset<16> bit_map_2nd;

    string bit_map_str = "";
    string new_bit_map_str = "";
    
    string ones = "#";
    string zeros = " ";

    for (int i = 0; i < n; i++)
    {
        bit_map_1st = arr1[i];
        bit_map_2nd = arr2[i];

        bit_map_1st = bit_map_1st | bit_map_2nd;

        bit_map_str = bit_map_1st.to_string();
        new_bit_map_str = bit_map_str.substr(16 - n, n);

        cout << new_bit_map_str << '\n';

        string decoded = "";
        for (int j = 0 ; j < n; j++)
        {
            if (new_bit_map_str[j] == '1')
            {
                decoded.append(ones);
            }
            else if (new_bit_map_str[j] == '0')
            {
                decoded.append(zeros);
            }
        }
        answer.push_back(decoded);
    }

    return answer;
}

 

 


๋‚˜์ค‘์— ์ƒ๊ฐํ•ด๋ณด๋‹ˆ๊นŒ ์‚ฌ์‹ค bitset ์„ ์•ˆ์จ๋„ ๋น„ํŠธ ์—ฐ์‚ฐ์ด ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€์ด๊ฐ€ ๊ฐ€๋Šฅํ–ˆ์—ˆ๋‹ค..

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments