[BOJ] 1032
명령 프롬프트
1032번 https://www.acmicpc.net/problem/1032
분류
- 
    
Bronze 1
 - 구현
 - 문자열
 
해법
하나의 패턴으로 모든 파일이 나와야하므로 모든 파일명의 공통된 부분을 제외한 부분만 ? 로 바꿔주면 됩니다.
정답 코드
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    string pattern;
    string file;
    int N;
    cin >> N;
    cin >> file;
    pattern = file; // initial state of pattern
    for (int i = 0; i < N - 1; i++)
    {
        cin >> file;
        for (int j = 0; j < pattern.length(); j++) 
        {
            if (pattern[j] != file[j]) // change different part of pattern as '?'
                pattern[j] = '?';
        }
    }
    cout << pattern;
    return 0;
}
Leave a comment