백준 1032 - 명령 프롬프트

황재진·2024년 3월 2일

백준

목록 보기
10/54
post-thumbnail

입력받은 문자열의 길이가 동일하다는 전제가 있어 단순히 동일선상의 문자들을 비교해주고 동일하다면 그대로, 아니면 "?"를 출력하면 되는 문제입니다.

#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;
}
profile
프로그래밍, 쉐이더 등 이것저것 다해보는 게임 개발자입니다

0개의 댓글