문제 링크

문제 설명

예시

[input]
3
cbaa
daacc
acacac

[output]
aac


[input]
3
a
aa
b

[output]
[빈라인]

사고의 흐름

모범답안

1. 여기를 누르면 답이 보입니다
from collections import Counter
import string

def counterWithDefaultValue(arr, defaultValue):
    dic = Counter(arr)
    for k in dic.keys():
        dic[k] = defaultValue
    return dic

def answer(arr, n):
    _max = 50
    alphabets = [c for c in string.ascii_lowercase]
    dic = Counter(alphabets)
    for i in range(n):
        for a in alphabets:
            if a in arr[i]: dic[a] += 1
    commonAlphabets = []
    for k, v in dic.items():
        if v == (n+1): commonAlphabets.append(k)
    if len(commonAlphabets) == 0: return ''
    dic = counterWithDefaultValue(commonAlphabets, _max)
    for i in range(n):
        _dic = Counter(arr[i])
        for k in dic.keys():
            dic[k] = min(dic[k], _dic[k])
    lexicalSortedKeys = sorted(dic.keys())
    result = []
    for i in range(len(lexicalSortedKeys)):
        k = lexicalSortedKeys[i]
        result = result + ([k] * dic[k])
    return "".join(result)

n = int(input())
arr = []
for _ in range(n):
    s = input().rstrip()
    arr.append([c for c in s])
print(answer(arr, n))

코드가 좀 더럽긴 한데, 두번만에 맞췄다~

2. 여기를 누르면 답이 보입니다