입력받은 문자열의 길이가 동일하다는 전제가 있어 단순히 동일선상의 문자들을 비교해주고 동일하다면 그대로, 아니면 "?"를 출력하면 되는 문제입니다.
#include <iostream>
#include <string>
int main()
{
int n;
std::cin >> n;
std::string* strs = new std::string[n];
for (int i = 0; i < n; i++)
{
std::cin >> strs[i];
}
int len = strs[0].length();
for (int i = 0; i < len; i++)
{
bool isCorrect = true;
char temp = strs[0][i];
for (int j = 1; j < n; j++)
{
if (temp != strs[j][i])
{
isCorrect = false;
break;
}
}
if (isCorrect)
std::cout << temp;
else
std::cout << "?";
}
delete[] strs;
return 0;
}