문제 링크입니다: https://www.acmicpc.net/problem/1032
흥미로운 문제였습니다.
알고리즘은 아래와 같습니다.
1. 주어지는 문자열들의 길이는 모두 같지만 문자열의 길이를 모르므로 string result를 선언하여 첫 번째 문자열과 똑같이 저장합니다.
2. 2번째부터 N번째 문자열을 첫번째 문자열과 비교해 다른 인덱스들을 모두 '?'으로 저장합니다.
3. result을 출력합니다.
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
string s;
cin >> s;
string result = s;
for (int i = 1; i < N; i++)
{
string temp;
cin >> temp;
for (int j = 0; j < s.length(); j++)
if (s[j] != temp[j])
result[j] = '?';
}
cout << result << "\n";
return 0;
}
개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
'알고리즘 > BOJ' 카테고리의 다른 글
백준 5598번 카이사르 암호 (0) | 2018.10.27 |
---|---|
백준 11656번 접미사 배열 (0) | 2018.10.27 |
백준 10808번 알파벳 개수 (0) | 2018.10.27 |
백준 1316번 그룹 단어 체커 (0) | 2018.10.27 |
백준 5622번 다이얼 (0) | 2018.10.27 |