본문 바로가기
백준

[C++] 백준 1032번: 명령 프롬프트

by MINU.SHINNNN 2023. 1. 15.

풀이

가장 처음 등장하는 파일명을 기준으로, 이후 등장하는 파일명에 대해 for loop로 문자를 하나하나 비교하며 '?' 처리를 한다.

#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
    freopen("1032.txt", "r", stdin); 
    int N;
    cin >> N;
    string str, cmp_str;
    cin >> str;
    if (N == 1) {
        cout << str << endl;
        return 0;
    }
    // 문자열 하나를 기준으로 ? 처리 
    for (int i = 0; i < N-1; i++) {
        cin >> cmp_str;  
        for (int j = 0; j < str.size(); j++) {
            if (str[j] == '?') continue;
            if (cmp_str[j] != str[j]) {
                str[j] = '?';
            }
        }
    }

    cout << str << endl;
    return 0;
}