알고리즘 문제풀이
[백준/BOJ] 백준 1032번 : 명령 프롬프트
GeniusJo
2020. 9. 17. 22:56
1032번: 명령 프롬프트
첫째 줄에 파일 이름의 개수 N이 주어진다. 둘째 줄부터 N개의 줄에는 파일 이름이 주어진다. N은 50보다 작거나 같은 자연수이고 파일 이름의 길이는 모두 같고 길이는 최대 50이다. 파일이름은 ��
www.acmicpc.net
파일 이름의 하나의 문자마다 다른 파일 이름과 같은지 확인한다
코드
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int n;
vector<string> name;
int main()
{
cin.tie(NULL);
ios_base::sync_with_stdio(false);
string input;
string result = "";
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> input;
name.push_back(input);
}
//파일이름의 하나의 문자마다 다른 파일이름과 같은지 확인한다
for (int i = 0; i < name[0].size(); i++)
{
bool same = true;
for (int j = 1; j < name.size(); j++)
{
//i위치의 문자가 다른 파일이름이 있을때
if (name[j - 1][i] != name[j][i])
{
same = false;
break;
}
}
//i위치의 문자가 모두 같을때
if (same == true)
result += name[0][i];
//i위치의 문자가 다른 파일이 있을때
else
result += "?";
}
cout << result;
return 0;
}