Algorithm, Data structure/Solved Algorithmic Problem

BAEKJOON 1032 - 명령 프롬프트

JaykayChoi 2016. 9. 29. 16:37

문제: https://www.acmicpc.net/problem/1032



오랜만에 손에 잡은 문제이자, 문제가 너무 쉬워 어딘가에 함정이 있을거라 한참을 찾아본 문제네요 ㅋㅋ;  




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <fstream>
#include <iostream>
#include <cstring>
#include <climits>
#include <algorithm>
 
#include <string>
 
using namespace std;
const int MAX_N = 50;
 
int main()
{
    string characters[MAX_N][MAX_N];
 
    int n;
    int strLength = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string str;
        cin >> str;
        strLength = str.length();
        for (int j = 0; j < strLength; j++)
            characters[i][j] = str[j];
    }
 
    string ret = "";
 
    for (int x = 0; x < strLength; x++)
    {
        string c = characters[0][x];
        bool isSame = true;
        for (int y = 1; y < n; y++)
        {
            if (c != characters[y][x])
            {
                isSame = false;
                ret += "?";
                break;
            }
        }
        if (isSame)
            ret += c;
    }
 
    cout << ret << endl;
 
    return 0;
}
cs