본문 바로가기
[프로그래머스 C++]/LEVEL 1

[프로그래머스 C++]

by AKI(JUNI) 2025. 3. 31.

◈ 문제 설명


◈ 문제 설명 링크

코딩테스트 연습 - [1차] 비밀지도 | 프로그래머스 스쿨

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 


◈ 작성 코드

#include <string>
#include <vector>
#include <stack>

using namespace std;

vector<string> solution(int n, vector<int> arr1, vector<int> arr2) 
{
    vector<string> answer;
    string ace = "";
    string beta = "";
    string zeta = "";
    string seta = "";
    
    for(int i = 0; i < arr1.size(); i++)
    {
        int t = arr1[i];
        
        for(int j = 0; j < n; j++)
        {
            if(t % 2 == 1)
            {
                ace += '1';
            }
            else
            {
                ace += '0';
            }
            t /= 2;
        }
        
        int k = arr2[i];
        
        for(int e = 0; e < n; e++)
        {
            if(k % 2 == 1)
            {
                beta += '1';
            }
            else
            {
                beta += '0';
            }
            k /= 2;
        }
        
        for(int g = 0; g < ace.size(); g++)
        {
            if(ace[g] == beta[g])
            {
                if(ace[g] == '1')
                {
                    zeta += '#';
                }
                else
                {
                    zeta += ' ';
                }
            }
            else
            {
                zeta += '#';
            }
        }
        
        for(int l = zeta.size() - 1; l >= 0; l--)
        {
            seta += zeta[l];
        }
        answer.push_back(seta);
        ace = "";
        beta = "";
        zeta = "";
        seta = "";
    }
    return answer;
}