알고리즘
[C++]백준 1032번: 명령 프롬프트
Kwoncorin
2020. 5. 24. 22:01
728x90
https://www.acmicpc.net/problem/1032
1032번: 명령 프롬프트
첫째 줄에 파일 이름의 개수 N이 주어진다. 둘째 줄부터 N개의 줄에는 파일 이름이 주어진다. N은 50보다 작거나 같은 자연수이고 파일 이름의 길이는 모두 같고 길이는 최대 50이다. 파일이름은 ��
www.acmicpc.net
1. 문제 설명
문자열을 입력받아서 문자열 글자가 같을 경우에는 문자열 글자를 그대로 출력하고, 다를 경우 '?'을 출력한다.
시간 복잡도 O(n^2)을 사용하였다.
2. 코드
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
cin.tie(NULL);
ios::sync_with_stdio(false);
int num;
cin >> num;
string* input = new string[num];
for (int x = 0; x < num; x++)
cin >> input[x];
int len = input[0].length();
for (int x = 0; x < len; x++)
{
char base = input[0][x];
bool check = true;
for (int y = 1; y < num; y++)
{
if (base != input[y][x])
{
check = false;
break;
}
}
if (check)
cout << base;
else
cout << "?";
}
return 0;
}
728x90