def compose_hangul(text): r=[] i=0 n=len(text) while i<n: if text[i] in CHOSUNG and i+1<n and text[i+1] in JUNGSUNG: c=text[i] v=text[i+1] i+=2
if i<n and text[i] in JUNGSUNG and (v,text[i]) in COMPOSE_V: v=COMPOSE_V[(v,text[i])] i+=1
f=''
if i<n and text[i] in JONGSUNG: if not (i+1<n and text[i+1] in JUNGSUNG): f=text[i] i+=1 if i<n and text[i] in JONGSUNG and not (i+1<n and text[i+1] in JUNGSUNG): if (f,text[i]) in COMPOSE_J: f=COMPOSE_J[(f,text[i])] i+=1
댓글
7개이게 무슨 뜻이죠??????
"fmf dlsxjsptdp cuqhtpdy"
해석용 코드입니다.
a = ["`","₩","1","2","3","4","5","6","7","8","9","0","-","=","q","w","e","r","t","y","u","i","o","p","[","]","\\",
"a","s","d","f","g","h","j","k","l",";","'","\"","z","x","c","v","b","n","m",",",".","/","~","!","@","#","$","%",
"^","&","*","(",")","_","+","Q","W","E","R","T","Y","U","I","O","P","{","}","|","A","S","D","F","G","H","J","K",
"L",":","Z","X","C","V","B","N","M","<",">","?"," "]
b = ["`","₩","1","2","3","4","5","6","7","8","9","0","-","=","ㅂ","ㅈ","ㄷ","ㄱ","ㅅ","ㅛ","ㅕ","ㅑ","ㅐ","ㅔ",
"[","]","\\","ㅁ","ㄴ","ㅇ","ㄹ","ㅎ","ㅗ","ㅓ","ㅏ","ㅣ",";","'","\"","ㅋ","ㅌ","ㅊ","ㅍ","ㅠ","ㅜ","ㅡ",
",",".","/","~","!","@","#","$","%","^","&","*","(",")","_","+","ㅃ","ㅉ","ㄸ","ㄲ","ㅆ","ㅛ","ㅕ","ㅑ","ㅒ",
"ㅖ","{","}","|","ㅁ","ㄴ","ㅇ","ㄹ","ㅎ","ㅗ","ㅓ","ㅏ","ㅣ",":","ㅋ","ㅌ","ㅊ","ㅍ","ㅠ","ㅜ","ㅡ","<",
">", "?"," "]
mapping = dict(zip(a, b))
CHOSUNG = ['ㄱ','ㄲ','ㄴ','ㄷ','ㄸ','ㄹ','ㅁ','ㅂ','ㅃ','ㅅ','ㅆ','ㅇ','ㅈ','ㅉ','ㅊ','ㅋ','ㅌ','ㅍ','ㅎ']
JUNGSUNG = ['ㅏ','ㅐ','ㅑ','ㅒ','ㅓ','ㅔ','ㅕ','ㅖ','ㅗ','ㅘ','ㅙ','ㅚ','ㅛ','ㅜ','ㅝ','ㅞ','ㅟ','ㅠ','ㅡ','ㅢ','ㅣ']
JONGSUNG = ['','ㄱ','ㄲ','ㄳ','ㄴ','ㄵ','ㄶ','ㄷ','ㄹ','ㄺ','ㄻ','ㄼ','ㄽ','ㄾ','ㄿ','ㅀ','ㅁ','ㅂ','ㅄ','ㅅ','ㅆ','ㅇ','ㅈ','ㅊ','ㅋ','ㅌ','ㅍ','ㅎ']
COMPOSE_V = {('ㅗ','ㅏ'):'ㅘ',('ㅗ','ㅐ'):'ㅙ',('ㅗ','ㅣ'):'ㅚ',('ㅜ','ㅓ'):'ㅝ',('ㅜ','ㅔ'):'ㅞ',('ㅜ','ㅣ'):'ㅟ',('ㅡ','ㅣ'):'ㅢ'}
COMPOSE_J = {('ㄱ','ㅅ'):'ㄳ',('ㄴ','ㅈ'):'ㄵ',('ㄴ','ㅎ'):'ㄶ',('ㄹ','ㄱ'):'ㄺ',('ㄹ','ㅁ'):'ㄻ',
('ㄹ','ㅂ'):'ㄼ',('ㄹ','ㅅ'):'ㄽ',('ㄹ','ㅌ'):'ㄾ',('ㄹ','ㅍ'):'ㄿ',('ㄹ','ㅎ'):'ㅀ',('ㅂ','ㅅ'):'ㅄ'}
def to_jamo(t):
return ''.join(mapping.get(c,c) for c in t)
def compose(c,v,f=''):
return chr(0xAC00 + (CHOSUNG.index(c)*21 + JUNGSUNG.index(v))*28 + JONGSUNG.index(f))
def compose_hangul(text):
r=[]
i=0
n=len(text)
while i<n:
if text[i] in CHOSUNG and i+1<n and text[i+1] in JUNGSUNG:
c=text[i]
v=text[i+1]
i+=2
if i<n and text[i] in JUNGSUNG and (v,text[i]) in COMPOSE_V:
v=COMPOSE_V[(v,text[i])]
i+=1
f=''
if i<n and text[i] in JONGSUNG:
if not (i+1<n and text[i+1] in JUNGSUNG):
f=text[i]
i+=1
if i<n and text[i] in JONGSUNG and not (i+1<n and text[i+1] in JUNGSUNG):
if (f,text[i]) in COMPOSE_J:
f=COMPOSE_J[(f,text[i])]
i+=1
r.append(compose(c,v,f))
else:
r.append(text[i])
i+=1
return ''.join(r)
if __name__=="__main__":
try:
n = int(input("입력할 줄 수를 입력하시오: "))
except:
n = 1
for _ in range(n):
print(compose_hangul(to_jamo(input())))
에러 뜨는데?
들여쓰기는 알아서하시오~
둘여 쓰기해주세요
알아서하시오
히든 문제 풀었습니다....
댓글 쓰기
댓글을 작성하려면 로그인하세요.