Notice
Recent Posts
Recent Comments
- Today
- Total
01-26 01:17
Tags
- ์์์ ๋ ฌ
- ์ธํด
- ์๋ฐ์์ ์
- ์๋ฃ๊ตฌ์กฐ
- tree
- ๋ฐฑ์๋
- BFS
- OOP
- leetcode
- database
- MST
- ๋ฐฑ์ค
- ๊ทธ๋ฆฌ๋
- ๋ฒจ๋งํฌ๋
- ์กธ์ ์ํ
- Algorithm
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ์๋ฐ
- ๋ฌธ๋ฒ
- ๋ค์ต์คํธ๋ผ
- ๊ตฌํ
- java
- dp
- PS
- array
- ํ๋ก๊ทธ๋๋จธ์ค
- Graph
- pytorch
- CS
- spring
Link
Partially Committed
[2018 KAKAO BLIND RECRUITMENT] (1์ฐจ) ๋น๋ฐ์ง๋ ๋ณธ๋ฌธ
๐ฅ Algorithm || ๋ฌธ์ ํ์ด/PS
[2018 KAKAO BLIND RECRUITMENT] (1์ฐจ) ๋น๋ฐ์ง๋
WonderJay 2022. 7. 5. 17:25728x90
๋ฐ์ํ
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/17681
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
'๐ฅ Algorithm || ๋ฌธ์ ํ์ด > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[2018 KAKAO BLIND RECRUITMENT] (1์ฐจ) ๋คํธ ๊ฒ์ (0) | 2022.07.06 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ฐ์ด๋ฐ ๊ธ์ ๊ฐ์ ธ์ค๊ธฐ (0) | 2022.07.05 |
[์ํด๋ฆฌ ์ฑ๋ฆฐ์ง] ๋ถ์กฑํ ๊ธ์ก ๊ณ์ฐํ๊ธฐ (0) | 2022.07.05 |
[์๊ฐ ์ฝ๋ ์ฑ๋ฆฐ์ง ์์ฆ3] ๋๋จธ์ง๊ฐ 1์ด ๋๋ ์ ์ฐพ๊ธฐ (0) | 2022.07.05 |
[์ํด๋ฆฌ ์ฑ๋ฆฐ์ง] ์ต์์ง์ฌ๊ฐํ (0) | 2022.07.04 |
Comments