Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. big_unit_list = ['조','억','만']
  2. small_unit_list = ['천','백','십']
  3. num_dict = {'일': 1, '이': 2, '삼': 3, '사': 4, '오': 5, '육': 6, '칠': 7, '팔': 8, '구': 9}
  4.  
  5. DATA = [
  6. ['오백삼십조칠천팔백구십만천오백삼십구', '삼조사천이만삼천구'],
  7. ['육십사억삼천이만팔만칠천육백구', '사십삼'],
  8. ['구백육십조칠천억팔천백삼십이만칠천일', '사십삼조오천이백억육천구백십만일'],
  9. ['이천구백육십조천오백칠십만삼천구백구십', '삼천사백오십조일억이천만육백사십삼'],
  10. ['사십오억삼천육십만오백구십', '칠십억천이백삼십오만칠천구십이'],
  11. ['천백십일', '구천오백구십구'],
  12. ['오억사천', '백십일'],
  13. ['만오천사백삼십', '십구만삼천오백'],
  14. ['일조', '삼'],
  15. ['일억', '만'],
  16. ]
  17.  
  18. def str2num(input_string):
  19. a = input_string
  20.  
  21. prev = 0
  22.  
  23. a_list = [[], [], [], []]
  24. for idx, x in enumerate(a):
  25. if x in big_unit_list:
  26. a_list[big_unit_list.index(x)].append(a[prev:idx])
  27. prev = idx + 1
  28. a_list[3].append(a[prev:])
  29.  
  30. for big_idx, a_unit in enumerate(a_list):
  31. a_small_list = [[], [], [], []]
  32. if a_unit:
  33. prev = 0
  34. for idx, x in enumerate(a_unit[0]):
  35. if x in small_unit_list:
  36. a_small_list[small_unit_list.index(x)].append(a_unit[0][prev:idx])
  37. prev = idx + 1
  38. a_small_list[3].append(a_unit[0][prev:])
  39. a_list[big_idx] = a_small_list
  40.  
  41. a_ret = [[], [], [], []]
  42. for idx_big, a_big in enumerate(a_list):
  43. new_str = ''
  44. for idx_small, a_small in enumerate(a_big):
  45. if a_small and a_small[0] in num_dict:
  46. new_str += str(num_dict[a_small[0]])
  47. else:
  48. if idx_small:
  49. new_str += str(0)
  50. else:
  51. pass
  52. a_ret[idx_big] = new_str
  53.  
  54. for idx, x in enumerate(a_ret):
  55. if not x:
  56. a_ret[idx] = '0000'
  57. else:
  58. while (len(a_ret[idx]) < 4):
  59. a_ret[idx] = '0' + a_ret[idx]
  60.  
  61. return int("".join(a_ret))
  62.  
  63. for pair in DATA:
  64. x, y = pair
  65.  
  66. x_num, y_num = str2num(x), str2num(y)
  67. print(x_num + y_num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement