알고리즘

[알고리즘] 백준 2804 - 크로스워드 만들기 (C++)

blueberrysoda 2024. 12. 19. 23:48

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

#include <iostream>
using namespace std;

int main(){
    string A, B;
    int a = -1, b = -1;
    bool f = false;

    cin >> A >> B;

    for(int i=0; i<A.size(); i++){
        for(int j=0; j<B.size(); j++){
            if(A[i] == B[j]){
                a = i;
                b = j;
                f = true;
                break;
            }
        }
        if(f == true){
            break;
        }
    }

    for(int i=0; i<B.size(); i++){
        if(i == b){
            cout << A << "\n";
            continue;
        }
        for(int j=0; j<A.size(); j++){
            if(j == a){
                cout << B[i];
            }
            else{
                cout << ".";
            }
        }
        cout << "\n";
    }
    return 0;
}