# 자음 매핑 (숫자 -> 자음 그룹)
consonant_map = {
'4': ['ㄱ', 'ㅋ'],
'5': ['ㄴ', 'ㄹ'],
'6': ['ㄷ', 'ㅌ'],
'7': ['ㅂ', 'ㅍ'],
'8': ['ㅅ', 'ㅎ'],
'9': ['ㅈ', 'ㅊ'],
'0': ['ㅇ', 'ㅁ'],
}
# 모음 매핑 (숫자 시퀀스 -> 완성된 모음 문자)
vowel_combinations = {
'12': 'ㅏ', '122': 'ㅑ', '21': 'ㅓ', '221': 'ㅕ',
'23': 'ㅗ', '223': 'ㅛ', '32': 'ㅜ', '322': 'ㅠ',
'3': 'ㅡ', '1': 'ㅣ', '211': 'ㅔ', '121': 'ㅐ',
'321': 'ㅟ', '231': 'ㅚ', '1221': 'ㅒ', '2211': 'ㅖ',
'2312': 'ㅘ', '23121': 'ㅙ', '3221': 'ㅝ', '32211': 'ㅞ',
'31': 'ㅢ'
}
# 초성, 중성, 종성 테이블
choseong_list = ['ㄱ','ㄲ','ㄴ','ㄷ','ㄸ','ㄹ','ㅁ','ㅂ','ㅃ','ㅅ','ㅆ','ㅇ','ㅈ','ㅉ','ㅊ','ㅋ','ㅌ','ㅍ','ㅎ']
jungseong_list = ['ㅏ','ㅐ','ㅑ','ㅒ','ㅓ','ㅔ','ㅕ','ㅖ','ㅗ','ㅘ','ㅙ','ㅚ','ㅛ','ㅜ','ㅝ','ㅞ','ㅟ','ㅠ','ㅡ','ㅢ','ㅣ']
jongseong_list = ['','ㄱ','ㄲ','ㄳ','ㄴ','ㄵ','ㄶ','ㄷ','ㄹ','ㄺ','ㄻ','ㄼ','ㄽ','ㄾ','ㄿ','ㅀ','ㅁ','ㅂ','ㅄ','ㅅ','ㅆ','ㅇ','ㅈ','ㅊ','ㅋ','ㅌ','ㅍ','ㅎ']
def make_hangul(choseong, jungseong, jongseong=''):
try:
cho_idx = choseong_list.index(choseong)
jung_idx = jungseong_list.index(jungseong)
jong_idx = jongseong_list.index(jongseong) if jongseong else 0
return chr(0xAC00 + (cho_idx * 21 * 28) + (jung_idx * 28) + jong_idx)
except ValueError:
return choseong + jungseong + jongseong
def parse_single_char(input_chunk):
idx = 0
cho, jung, jong = '', '', ''
if input_chunk[idx] in consonant_map:
repeat = 1
while idx + repeat < len(input_chunk) and input_chunk[idx + repeat] == input_chunk[idx]:
repeat += 1
cho = consonant_map[input_chunk[idx]][(repeat - 1) % len(consonant_map[input_chunk[idx]])]
idx += repeat
else:
cho = 'ㅇ'
jung = ''
for j in range(len(input_chunk), idx, -1):
candidate = input_chunk[idx:j]
if candidate in vowel_combinations:
jung = vowel_combinations[candidate]
idx = j
break
if idx < len(input_chunk) and input_chunk[idx] in consonant_map:
repeat = 1
while idx + repeat < len(input_chunk) and input_chunk[idx + repeat] == input_chunk[idx]:
repeat += 1
jong = consonant_map[input_chunk[idx]][(repeat - 1) % len(consonant_map[input_chunk[idx]])]
return make_hangul(cho, jung, jong)
# ⬇️ 사용자 입력 받기
user_input = input("숫자 입력 (공백으로 각 글자 구분): ").strip()
chunks = user_input.split()
result = ''.join(parse_single_char(chunk) for chunk in chunks)
print("결과:", result)# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
print("Try programiz.pro")