백준 1032 c++

magicdrill·2024년 7월 2일

백준 문제풀이

목록 보기
382/673

백준 1032 c++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void input_file(vector<string>& file)
{
	int i, N;
	string temp;

	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> temp;
		file.push_back({ temp });
	}

	return;
}

void find_answer(vector<string>& file)
{
	int i, j;
	string answer = "";
	bool all_same = true;

	if (file.size() == 1)
	{
		cout << file[0] << "\n";
		return;
	}
	for (i = 0; i < file[0].length(); i++)
	{
		for (j = 1; j < file.size(); j++)
		{
			if (file[j][i] == file[j - 1][i])
			{
				all_same = true;
			}
			else
			{
				all_same = false;
				break;
			}
		}
		if (all_same)
		{
			answer += file[0][i];
		}
		else
		{
			answer += '?';
		}
	}
	cout << answer << "\n";

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	vector<string> file;

	input_file(file);
	find_answer(file);

	return 0;
}

0개의 댓글