[알고리즘] 프로그래머스_비밀지도

Fortice·2021년 6월 29일
0

알고리즘

목록 보기
11/18

본 블로그는 비상업적, 비영리적 용도의 학업만을 위해 글을 게시합니다.

1. 문제 분석

  • 간단한 bit 표시 문제같다.
  • 두 배열의 값을 OR 해주고 2진법으로 표시해 #을 해주면 될 것 같다.

2. 문제 풀이 과정(삽질)

  • 쉬운 문제이다.

3. 문제 해결

  • 분석대로 했다.

4. 코드

#include <string>
#include <vector>

using namespace std;

vector<string> solution(int n, vector<int> arr1, vector<int> arr2) {
    char line[17] = {0};
    vector<string> answer;
    
    for(int i = 0; i < n; i++)
    {
        int now = arr1[i] | arr2[i];
        for(int j = n - 1; j >= 0; j--)
        {
            line[j] = (now % 2) ? '#' : ' ';
            now >>= 1;
        }
        string line_str(line, n);
        answer.push_back(line_str);
    }
    return answer;
}
profile
서버 공부합니다.

0개의 댓글