Created
July 13, 2021 13:26
-
-
Save rkdgusrnrlrl/aecfdfe71343f82fd89b43c6e9614ef2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
kor_num = {'영': 0, '일': 1, '이': 2, '삼': 3, '사': 4, '오': 5, | |
'육': 6, '칠': 7, '팔': 8, '구': 9, '십': 10, '백': 100, '천': 1000, | |
'만': 10000, '억': 100000000, '조': 1000000000000 } | |
def int_kor(str_num): | |
num_strs = [ss for ss in str_num] | |
idx = 0 | |
total = 0 | |
totals = [] | |
while(len(num_strs) > idx): | |
kk = num_strs[idx] | |
num = kor_num[kk] | |
if num > 9999: | |
if total == 0: | |
total = 1 | |
totals.append(total * num) | |
total = 0 | |
idx += 1 | |
continue | |
if num < 10 and idx + 1 < len(num_strs): | |
next_num = kor_num[num_strs[idx+1]] | |
if next_num < 9999: | |
num = next_num * num | |
idx += 1 | |
total += num | |
idx += 1 | |
return sum(totals) + total | |
NUM_STR_LIST = ['영', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'] | |
MULTIPLE_TEN_STR_LIST = ['영', '십', '백', '천', '만', '십', '백', '천', '억', '십', '백', '천', '조', '십', '백', '천'] | |
def str_kor(num): | |
num_strs = [int(ss) for ss in str(num)] | |
num_strs.reverse() | |
str_num = NUM_STR_LIST[num_strs[0]] | |
if str_num == '영': | |
str_num = '' | |
for ii in range(1, len(num_strs)): | |
nn = num_strs[ii] | |
if (ii == 8 or ii == 12) and str_num[0] in '조억만': | |
str_num = str_num[1:] | |
if nn == 0: | |
if ii == 4 or ii == 8 or ii == 12: | |
str_num = MULTIPLE_TEN_STR_LIST[ii] + str_num | |
continue | |
str_num = MULTIPLE_TEN_STR_LIST[ii] + str_num | |
if ii == 4 or ii == 8 or ii == 12 or nn != 1: | |
str_num = NUM_STR_LIST[nn] + str_num | |
if str_num[:2] == '일만': | |
str_num = '만' + str_num[2:] | |
return str_num | |
if __name__ == "__main__": | |
arg1 = sys.argv[1] | |
f_str = [ss for ss in arg1] | |
f_num = int_kor(f_str) | |
arg2 = sys.argv[2] | |
s_str = [ss for ss in arg2] | |
s_num = int_kor(s_str) | |
print(str_kor(f_num + s_num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment