알고리즘

[알고리즘] 백준 2596 - 비밀편지 (C++)

blueberrysoda 2025. 4. 26. 23:24

[문제 링크] : https://www.acmicpc.net/problem/2596

#include <iostream>
#include <string>
using namespace std;

int N;
string S;
string Arr[8] = {"000000","001111","010011","011100","100110","101001","110101","111010"};

int cmp(string s, int n){
    int res = 0;
    for(int j=0; j<6; j++){
        if(Arr[n][j] != s[j]){
            res++;
        }
    }
    return res;
}

int main(){
    cin >> N >> S;
    string Ans;

    for(int i=0; i<N; i++){
        string tmp = S.substr(i*6, 6);
        bool flag = 0;

        for(int j=0; j<8; j++){
            if(cmp(tmp, j) <= 1){
                flag=1;
                Ans += ('A' + j);
                break;
            }
        }
        if(flag == false){
            cout << i+1;
            return 0;
        }
    }
    cout << Ans << "\n";
    return 0;
}