Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- big_unit_list = ['조','억','만']
- small_unit_list = ['천','백','십']
- num_dict = {'일': 1, '이': 2, '삼': 3, '사': 4, '오': 5, '육': 6, '칠': 7, '팔': 8, '구': 9}
- DATA = [
- ['오백삼십조칠천팔백구십만천오백삼십구', '삼조사천이만삼천구'],
- ['육십사억삼천이만팔만칠천육백구', '사십삼'],
- ['구백육십조칠천억팔천백삼십이만칠천일', '사십삼조오천이백억육천구백십만일'],
- ['이천구백육십조천오백칠십만삼천구백구십', '삼천사백오십조일억이천만육백사십삼'],
- ['사십오억삼천육십만오백구십', '칠십억천이백삼십오만칠천구십이'],
- ['천백십일', '구천오백구십구'],
- ['오억사천', '백십일'],
- ['만오천사백삼십', '십구만삼천오백'],
- ['일조', '삼'],
- ['일억', '만'],
- ]
- def str2num(input_string):
- a = input_string
- prev = 0
- a_list = [[], [], [], []]
- for idx, x in enumerate(a):
- if x in big_unit_list:
- a_list[big_unit_list.index(x)].append(a[prev:idx])
- prev = idx + 1
- a_list[3].append(a[prev:])
- for big_idx, a_unit in enumerate(a_list):
- a_small_list = [[], [], [], []]
- if a_unit:
- prev = 0
- for idx, x in enumerate(a_unit[0]):
- if x in small_unit_list:
- a_small_list[small_unit_list.index(x)].append(a_unit[0][prev:idx])
- prev = idx + 1
- a_small_list[3].append(a_unit[0][prev:])
- a_list[big_idx] = a_small_list
- a_ret = [[], [], [], []]
- for idx_big, a_big in enumerate(a_list):
- new_str = ''
- for idx_small, a_small in enumerate(a_big):
- if a_small and a_small[0] in num_dict:
- new_str += str(num_dict[a_small[0]])
- else:
- if idx_small:
- new_str += str(0)
- else:
- pass
- a_ret[idx_big] = new_str
- for idx, x in enumerate(a_ret):
- if not x:
- a_ret[idx] = '0000'
- else:
- while (len(a_ret[idx]) < 4):
- a_ret[idx] = '0' + a_ret[idx]
- return int("".join(a_ret))
- for pair in DATA:
- x, y = pair
- x_num, y_num = str2num(x), str2num(y)
- print(x_num + y_num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement