프로그래머스 - [1차] 비밀지도

well-life-gm·2021년 12월 20일
0

프로그래머스

목록 보기
94/125

프로그래머스 - [1차] 비밀지도

비트연산을 쓰면 코드가 깔끔해진다.

코드는 아래와 같다.

#include <string>
#include <vector>

using namespace std;

vector<string> solution(int n, vector<int> arr1, vector<int> arr2) {
    vector<string> answer(n);
    for(int i=0;i<n;i++) 
        for(int j=n-1;j>=0;j--) 
            answer[i].push_back((arr1[i] | arr2[i]) & (1 << j) ? '#' : ' ');
            
    return answer;
}

결과

profile
내가 보려고 만든 블로그

0개의 댓글