알고리즘

[알고리즘] 백준 14623 - 감정이입 (C++)

blueberrysoda 2025. 4. 25. 23:58

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

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

long long pow(int n){
    int res = 1;
    for(int i=0; i<n; i++){
        res *= 2;
    }
    return res;
}

string solve(long long n){
    string res = "";
    
    while(n > 0){
        res += n % 2 + '0';
        n /= 2;
    }
    reverse(res.begin(), res.end());
    
    return res;
}

int main(){
    string A, B;
    cin >> A >> B;
    long long a = 0, b = 0;
    int x = A.length(), y = B.length();

    for(int i=0; i<x; i++){
        a += A[i] == '1' ? pow(x - (i + 1)) : 0;
    }
    
    for(int i=0; i<y; i++){
        b += B[i] == '1' ? pow(y - (i + 1)) : 0;
    }

    string res = solve(a * b);

    cout << res << "\n";

    return 0;
}