풀이
가장 처음 등장하는 파일명을 기준으로, 이후 등장하는 파일명에 대해 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;
}
'백준' 카테고리의 다른 글
[C++] 백준 2839 설탕배달 DP (0) | 2023.01.16 |
---|---|
[C++] 백준 14502 연구소, Brute-Force, BFS (Gold 4) (0) | 2023.01.15 |
[C++] 백준 11724번 연결 요소의 개수 (Silver 2) (0) | 2023.01.15 |
[C++] 백준 2667번 단지 붙이기 (Silver 1) (0) | 2023.01.15 |
[C++] 백준 1254번: 팰린드롬 만들기 (Silver 2) (0) | 2023.01.15 |