fork download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main{
  5. /* **********************************************
  6. * 자음 모음 분리
  7. * 설연수 -> ㅅㅓㄹㅇㅕㄴㅅㅜ, 바보 -> ㅂㅏㅂㅗ
  8. * **********************************************/
  9. /** 초성 - 가(ㄱ), 날(ㄴ) 닭(ㄷ) */
  10. public static char[] arrChoSung = { 0x3131, 0x3132, 0x3134, 0x3137, 0x3138,
  11. 0x3139, 0x3141, 0x3142, 0x3143, 0x3145, 0x3146, 0x3147, 0x3148,
  12. 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e };
  13. /** 중성 - 가(ㅏ), 야(ㅑ), 뺨(ㅑ)*/
  14. public static char[] arrJungSung = { 0x314f, 0x3150, 0x3151, 0x3152,
  15. 0x3153, 0x3154, 0x3155, 0x3156, 0x3157, 0x3158, 0x3159, 0x315a,
  16. 0x315b, 0x315c, 0x315d, 0x315e, 0x315f, 0x3160, 0x3161, 0x3162,
  17. 0x3163 };
  18. /** 종성 - 가(없음), 갈(ㄹ) 천(ㄴ) */
  19. public static char[] arrJongSung = { 0x0000, 0x3131, 0x3132, 0x3133,
  20. 0x3134, 0x3135, 0x3136, 0x3137, 0x3139, 0x313a, 0x313b, 0x313c,
  21. 0x313d, 0x313e, 0x313f, 0x3140, 0x3141, 0x3142, 0x3144, 0x3145,
  22. 0x3146, 0x3147, 0x3148, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e };
  23.  
  24.  
  25. /* **********************************************
  26. * 알파벳으로 변환
  27. * 설연수 -> tjfdustn, 멍충 -> ajdcnd
  28. * **********************************************/
  29. /** 초성 - 가(ㄱ), 날(ㄴ) 닭(ㄷ) */
  30. public static String[] arrChoSungEng = { "r", "R", "s", "e", "E",
  31. "f", "a", "q", "Q", "t", "T", "d", "w",
  32. "W", "c", "z", "x", "v", "g" };
  33.  
  34. /** 중성 - 가(ㅏ), 야(ㅑ), 뺨(ㅑ)*/
  35. public static String[] arrJungSungEng = { "k", "o", "i", "O",
  36. "j", "p", "u", "P", "h", "hk", "ho", "hl",
  37. "y", "n", "nj", "np", "nl", "b", "m", "ml",
  38. "l" };
  39.  
  40. /** 종성 - 가(없음), 갈(ㄹ) 천(ㄴ) */
  41. public static String[] arrJongSungEng = { "", "r", "R", "rt",
  42. "s", "sw", "sg", "e", "f", "fr", "fa", "fq",
  43. "ft", "fx", "fv", "fg", "a", "q", "qt", "t",
  44. "T", "d", "w", "c", "z", "x", "v", "g" };
  45.  
  46. /** 단일 자음 - ㄱ,ㄴ,ㄷ,ㄹ... (ㄸ,ㅃ,ㅉ은 단일자음(초성)으로 쓰이지만 단일자음으론 안쓰임) */
  47. public static String[] arrSingleJaumEng = { "r", "R", "rt",
  48. "s", "sw", "sg", "e","E" ,"f", "fr", "fa", "fq",
  49. "ft", "fx", "fv", "fg", "a", "q","Q", "qt", "t",
  50. "T", "d", "w", "W", "c", "z", "x", "v", "g" };
  51.  
  52.  
  53.  
  54. public static void main(String args[]) {
  55.  
  56. String word = "설연수 멍충아ㅏㅠkk!@#$%^&*()★"; // 분리할 단어
  57. String result = ""; // 결과 저장할 변수
  58. String resultEng = ""; // 알파벳으로
  59.  
  60. for (int i = 0; i < word.length(); i++) {
  61.  
  62. /* 한글자씩 읽어들인다. */
  63. char chars = (char) (word.charAt(i) - 0xAC00);
  64.  
  65. if (chars >= 0 && chars <= 11172) {
  66. /* A. 자음과 모음이 합쳐진 글자인경우 */
  67.  
  68. /* A-1. 초/중/종성 분리 */
  69. int chosung = chars / (21 * 28);
  70. int jungsung = chars % (21 * 28) / 28;
  71. int jongsung = chars % (21 * 28) % 28;
  72.  
  73.  
  74. /* A-2. result에 담기 */
  75. result = result + arrChoSung[chosung] + arrJungSung[jungsung];
  76.  
  77.  
  78. /* 자음분리 */
  79. if (jongsung != 0x0000) {
  80. /* A-3. 종성이 존재할경우 result에 담는다 */
  81. result = result + arrJongSung[jongsung];
  82. }
  83.  
  84. /* 알파벳으로 */
  85. resultEng = resultEng + arrChoSungEng[chosung] + arrJungSungEng[jungsung];
  86. if (jongsung != 0x0000) {
  87. /* A-3. 종성이 존재할경우 result에 담는다 */
  88. resultEng = resultEng + arrJongSungEng[jongsung];
  89. }
  90.  
  91. } else {
  92. /* B. 한글이 아니거나 자음만 있을경우 */
  93.  
  94. /* 자음분리 */
  95. result = result + ((char)(chars + 0xAC00));
  96.  
  97. /* 알파벳으로 */
  98. if( chars>=34097 && chars<=34126){
  99. /* 단일자음인 경우 */
  100. int jaum = (chars-34097);
  101. resultEng = resultEng + arrSingleJaumEng[jaum];
  102. } else if( chars>=34127 && chars<=34147) {
  103. /* 단일모음인 경우 */
  104. int moum = (chars-34127);
  105. resultEng = resultEng + arrJungSungEng[moum];
  106. } else {
  107. /* 알파벳인 경우 */
  108. resultEng = resultEng + ((char)(chars + 0xAC00));
  109. }
  110. }//if
  111.  
  112. }//for
  113.  
  114. System.out.println("============ result ==========");
  115. System.out.println("단어 : " + word);
  116. System.out.println("자음분리 : " + result);
  117. System.out.println("알파벳 : " + resultEng);
  118. }
  119. }
Success #stdin #stdout 0.22s 58352KB
stdin
Standard input is empty
stdout
============ result ==========
단어     : 설연수 멍충아ㅏㅠkk!@#$%^&*()★
자음분리 : ㅅㅓㄹㅇㅕㄴㅅㅜ ㅁㅓㅇㅊㅜㅇㅇㅏㅏㅠkk!@#$%^&*()★
알파벳   : tjfdustn ajdcnddkkbkk!@#$%^&*()★