한국어 2 세트 키보드와 쿼티 키보드 간 변환


14

소개

DVORAK 키보드 레이아웃 과 다소 비슷 하지만 훨씬 어렵습니다.

먼저 한국어 키보드에 대해 이야기합시다. Wikipedia 에서 볼 수 있듯이 한국어 및 영어 키 세트간에 변경하는 Kor / Eng 키가 있습니다.

한국인은 때때로 틀린 유형 : 쿼티 키보드에서 한국어로 또는 2 세트 키보드에서 영어로 쓰려고합니다.

따라서 문제는 다음과 같습니다. 두 세트 키보드로 한국어 문자를 입력하면 쿼티 키보드로 입력 한 알파벳 문자로 변환하십시오. 쿼티로 입력 된 알파벳 문자가 있으면 2 세트 키보드로 변경하십시오.

2 세트 키보드

다음은 2 세트 키보드 레이아웃입니다.

ㅂㅈㄷㄱㅅㅛㅕㅑㅐㅔ
 ㅁㄴㅇㄹㅎㅗㅓㅏㅣ
  ㅋㅌㅊㅍㅠㅜㅡ

그리고 shift 키로 :

ㅃㅉㄸㄲㅆㅛㅕㅑㅒㅖ

맨 위 줄만 바뀌고 다른 줄은 바뀌지 않습니다.

한글 정보

여기서 끝났다면 쉬울 수 있지만 쉽지 않습니다. 입력 할 때

dkssud, tprP!

출력은 다음과 같이 표시되지 않습니다.

ㅇㅏㄴㄴㅕㅇ, ㅅㅔㄱㅖ!

그러나 이런 식으로 :

안녕, 세계!(means Hello, World!)

그리고 일을 훨씬 어렵게 만듭니다.

한국어 문자는 '조성 (자음)', '정성 (음량)', '종성 (음절 끝의 자음 : 비워 둘 수 있음)'의 세 부분으로 구분되며 구분해야합니다.

다행히도 그렇게 할 수있는 방법이 있습니다.

분리하는 방법

초성 19 개, 중성 21 개, 종성 28 개 (공백 포함)가 있으며 0xAC00은 한자의 첫 문자 인 '가'입니다. 이를 사용하여 한자를 세 부분으로 나눌 수 있습니다. 다음은 2 세트 키보드에서 각각의 순서와 위치입니다.

choseong 주문 :

ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ
r R s e E f a q Q t T d w W c z x v g

중성 순서 :

ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ
k o i O j p u P h hk ho hl y n nj np nl b m ml l

종성 질서 :

()ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ
()r R rt s sw sg e f fr fa fq ft fx fv fg a q qt t T d w c z x v g

하자 말은 (unicode value of some character) - 0xAC00있다 Korean_code, 그리고 초성, Jungseong의 인덱스, Jongseong는 Cho, Jung,Jong .

그런 다음 Korean_code입니다(Cho * 21 * 28) + Jung * 28 + Jong

다음은 귀하의 편의를 위해 한글을이 한국어 웹 사이트와 구분하는 자바 스크립트 코드입니다 .

var rCho = [ "ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ" ];
var rJung =[ "ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ" ];
var rJong = [ "", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ","ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ" ];
var cho, jung, jong;
var sTest = "탱";
var nTmp = sTest.charCodeAt(0) - 0xAC00;
jong = nTmp % 28; // Jeongseong
jung = ((nTmp - jong) / 28 ) % 21 // Jungseong
cho = ( ( (nTmp - jong) / 28 ) - jung ) / 21 // Choseong

alert("Choseong:" + rCho[cho] + "\n" + "Jungseong:" + rJung[jung] + "\n" + "Jongseong:" + rJong[jong]);

조립할 때

  1. 그 주 ㅘ, ㅙ, ㅚ, ㅝ, ㅞ, ㅟ, ㅢ기타 jungseongs의 조합입니다.
ㅗ+ㅏ=ㅘ, ㅗ+ㅐ=ㅙ, ㅗ+ㅣ=ㅚ, ㅜ+ㅓ=ㅝ, ㅜ+ㅔ=ㅞ, ㅜ+ㅣ=ㅟ, ㅡ+ㅣ=ㅢ
  1. 초성이 필요합니다. 만약 수단, 즉 frk주어지고있는 ㄹㄱㅏ, 두 개의 방식으로 변경할 수있다 : ㄺㅏ및 ㄹ가. 그런 다음 선택한 방식으로 변환해야합니다. 경우 jjjrjr주어진되는 ㅓㅓㅓㄱㅓㄱ선도적 인 ㅓ들 초성 할 수 있습니다 아무것도하지 않지만, 네 번째 ㅓ가 ㄱ가로 바뀌도록, 즉 초성 할 수 있습니다 ㅓㅓㅓ걱.

다른 예 : 세계( tprP). 섹ㅖ( (ㅅㅔㄱ)(ㅖ)) (으 ) 로 변경할 수 있지만 chooseong이 필요하기 때문에 세계( (ㅅㅔ)(ㄱㅖ)) (으 ) 로 변경되었습니다.

예

입력 1

안녕하세요

출력 1

dkssudgktpdy

입력 2

input 2

출력 2

ㅑㅞㅕㅅ 2

입력 3

힘ㄴㄴ

출력 3

glass

입력 4

아희(Aheui) is esolang which you can program with pure Korean characters.

출력 4

dkgml(모뎌ㅑ) ㅑㄴ ㄷ내ㅣ뭏 조ㅑ초 ㅛㅐㅕ ㅊ무 ㅔ갷ㄱ므 쟈소 ㅔㅕㄱㄷ ㅏㅐㄱㄷ무 촘ㄱㅁㅊㅅㄷㄱㄴ.

입력 5

dkssud, tprP!

출력 5

안녕, 세계!

입력 6

ㅗ디ㅣㅐ, 째깅! Hello, World!

출력 6

hello, World! ㅗ디ㅣㅐ, 째깅!

가장 짧은 코드가 승리합니다. (바이트)

편의를위한 새로운 규칙

A2 세트 키보드에 해당 문자 가없는 문자를 해제 할 수 있습니다 . 그래서 Aheui에 Aㅗ뎌ㅑOK입니다. 변경할 경우에, Aheui에 모뎌ㅑ, 당신은 얻을 수 -5 점을, 당신은 5 바이트를 적립 할 수 있습니다.

당신은 (같은 두 jungseongs 분리 할 수 있습니다 ㅘ에를 ㅗ+ㅏ). , 또는 을 좋아 rhk합니다 . 당신이 (처럼 결합하지만 만약 에 나 에게 ), 당신은 추가 -5 포인트를 적립 할 수 있습니다.고ㅏhowㅗㅐㅈrhk과howㅙㅈ


에서 jungseong 주문 글자의 섹션 중 하나가 없습니다. 한국어 기호는 21 개이지만 글자는 20 자입니다. 편집 : 한글 기호 시험 l후 누락 된 것 같습니다 . mlㅣ
— Kevin Cruijssen

@KevinCruijssen 님이 편집했습니다. l ㅣ.
— LegenDUST

1
때로는 둘 이상의 해석이있을 수 있습니다. 예를 들어 또는 fjfau로 해석 될 수 있습니다 . 이 문제를 어떻게 해결합니까? 럶ㅕ럴며
— Nick Kennedy

1
@LegenDUST 글쎄, 한국어 한 단어를 읽을 수 없으므로 설명을 따라 가야합니다. ;에 대해서는 P tprP테스트 케이스 5 : 에이 변환 ㅅㅔㄱㅖ, ㅅ초성되고, ㅔjungseong이고 ㄱjongseong이다. 그래서이로 변환 should't 섷ㅖ(같은 그룹화 (ㅅㅔㄱ)(ㅖ)) 대신에 세계(같은 그룹화 (ㅅㅔ)(ㄱㅖ))? 이전 주석에서는 입력하여 해석한다고 말하므로 ㅅㅔㄱ로 변환 할 것으로 예상 됩니다 섷. 아니면 한국어가 왼쪽에서 오른쪽 대신 오른쪽에서 왼쪽으로 입력됩니까?
— Kevin Cruijssen

1
@KevinCruijssen Unicode.org의 PDF 파일 . AC00 ( 가) ~ D7AF ( 힣).
— LegenDUST

답변:


6

젤리 , 296,264 바이트

Ẏœṣjƭƒ
“ȮdȥŒ~ṙ7Ṗ:4Ȧịعʂ ="÷Ƥi-ẓdµ£f§ñỌ¥ẋaḣc~Ṡd1ÄḅQ¥_æ>VÑʠ|⁵Ċ³(Ė8ịẋs|Ṇdɼ⁼:Œẓİ,ḃṙɠX’ṃØẠs2ḟ€”A
“|zƒẉ“®6ẎẈ3°Ɠ“⁸)Ƙ¿’ḃ2’T€ị¢
¢ĖẈṪ$ÞṚƊ€
3£OŻ€3¦ŒpFḟ0Ɗ€J+“Ḥœ’,ƲyO2£OJ+⁽.[,Ʋ¤y¹ỌŒḊ?€µ¢ṖŒpZF€’ḋ588,28+“Ḥþ’Ʋ0;,ʋ/ṚƲ€ñṣ0ḊḢ+®Ṫ¤Ɗ;ṫ®$Ɗ¹Ḋ;⁶Ṫ⁼ṁ@¥¥Ƈ@¢ṪẈṪ‘;Ʋ€¤ḢƲ©?€ṭḢƲF2£żJ+⁽.[Ɗ$ẈṪ$ÞṚ¤ñỌ

온라인으로 사용해보십시오!

문자열을 인수로 사용하고 문자열을 암시 적으로 반환하는 전체 프로그램입니다 (암시 적으로 인쇄 됨). 이것은 세 단계로 작동합니다. 먼저 모든 한국어 문자를 라틴 문자의 코드 포인트 목록으로 변환합니다. 그런 다음 복합 한자를 식별하고 빌드합니다. 마지막으로, 남아있는 흩어진 라틴 문자를 한국어로 바꿉니다. 사양에 나타나지 않는 다른 문자 및 라틴 문자 (예 :) A는 그대로 남아 있습니다.

사양을 벗어난 소문자 대문자로 변환해야하는 경우 추가 10 바이트의 비용 으로 수행 할 수 있습니다 .

설명

헬퍼 링크 1 : 인수 x와 y를 가진 2 진 링크. x는 검색 및 교체 하위 목록 쌍의 목록입니다. y는 각 검색 하위 목록을 해당 대체 하위 목록으로 교체합니다.

Ẏ      | Tighten (reduce to a single list of alternating search and replace sublists)
     ƒ | Reduce using y as starting argument and the following link:
    ƭ  | - Alternate between using the following two links:
 œṣ    |   - Split at sublist
   j   |   - Join using sublist

도우미 링크 2 : 한국어 문자의 유니 코드 순서에 해당하는 순서로 라틴 문자 / 문자 쌍 목록

“Ȯ..X’          | Base 250 integer 912...
      ṃØẠ       | Base decompress into Latin letters (A..Za..z)
         s2     | Split into twos
           ḟ€”A | Filter out A from each (used as filler for the single characters)

도우미 링크 3 : 초성, 중성, 종성에 사용되는 라틴 문자 목록

“|...¿’        | List of base 250 integers, [1960852478, 2251799815782398, 2143287262]
       ḃ2      | Convert to bijective base 2
         ’     | Decrease by 1
          T€   | List of indices of true values for each list
            ị¢ | Index into helper link 2

도우미 링크 4 : 위의 라틴 문자 목록은 길이가 감소하는 순서로 열거 및 정렬됩니다.

¢         | Helper link 3 as a nilad
       Ɗ€ | For each list, the following three links as a monad
 Ė        | - Enumerate (i.e. prepend a sequential index starting at 1 to each member of the list)
    $Þ    | - Sort using, as a key, the following two links as a monad
  Ẉ       |   - Lengths of lists
   Ṫ      |   - Tail (this will be the length of the original character or characters)
      Ṛ   | - Reverse

메인 링크 : 젤리 문자열을 인자로 받아 번역 된 젤리 문자열을 반환하는 Monad

섹션 1 : 형태소 블록을 해당 라틴 문자의 유니 코드 코드 포인트로 변환

섹션 1.1 : 블록을 만드는 데 필요한 라틴 문자 목록 가져 오기

3£      | Helper link 3 as a nilad (lists of Latin characters used for Choseong, Jungseong and Jongseong)
  O     | Convert to Unicode code points
   Ż€3¦ | Prepend a zero to the third list (Jongseong)

섹션 1.2 :이 문자들의 모든 조합을 작성하십시오 (적절한 어휘 순서로 19 × 21 × 28 = 11,172 조합)

Œp      | Cartesian product
     Ɗ€ | For each combination:
  F     | - Flatten
   ḟ0   | - Filter zero (i.e. combinations with an empty Jonseong)

섹션 1.3 : 블록의 유니 코드 코드 포인트를 해당 라틴 문자 목록과 쌍을 이루고이를 사용하여 입력 문자열의 형태소 블록을 변환하십시오

       Ʋ   | Following as a monad
J          | - Sequence from 1..11172
 +“Ḥœ’     | - Add 44031
      ,    | - Pair with the blocks themelves
        y  | Translate the following using this pair of lists
         O | - The input string converted to Unicode code points

섹션 2 : 섹션 1의 출력에서 ​​개별 한국어 문자를 라틴 문자의 코드 포인트로 변환

          ¤  | Following as a nilad
2£           | Helper link 2 (list of Latin characters/character pairs in the order that corresponds to the Unicode order of the Korean characters)
  O          | Convert to Unicode code points
         Ʋ   | Following as a monad:
   J         | - Sequence along these (from 1..51)
    +⁽.[     | - Add 12592
        ,    | - Pair with list of Latin characters
           y | Translate the output from section 1 using this mapping

섹션 3 : 섹션 2의 출력에서 ​​번역되지 않은 문자 정리 (한국어로 번역 된 항목이 하위 목록에 있고 깊이가 1이므로 작동 함)

  ŒḊ?€  | For each member of list if the depth is 1:
¹       | - Keep as is
 Ọ      | Else: convert back from Unicode code points to characters
      µ | Start a new monadic chain using the output from this section as its argument

섹션 4 : 라틴 문자의 형태소 블록을 한국어로 변환

섹션 4.1 : 가능한 모든 조성 및 정성 조합

¢    | Helper link 4 (lists of Latin characters enumerated and sorted in decreasing order of length)
 Ṗ   | Discard last list (Jongseong)
  Œp | Cartesian product

섹션 4.2 : 기본 형태 블록의 유니 코드 코드 포인트로 각 조합에 레이블을 붙입니다 (즉, 종성 없음)

                       Ʋ€ | For each Choseong/Jungseong combination
Z                         | - Transpose, so that we now have e.g. [[1,1],["r","k"]]
 F€                       | - Flatten each, joining the strings together
                    ʋ/    | - Reduce using the following as a dyad (effectively using the numbers as left argument and string of Latin characters as right)
                Ʋ         |   - Following links as a monad
   ’                      |     - Decrease by 1
    ḋ588,28               |     - Dot product with 21×28,28
           +“Ḥþ’          |     - Add 44032
                 0;       |     - Prepend zero; used for splitting in section 4.3 before each morphemic block (Ż won’t work because on a single integer it produces a range)
                   ,      |     - Pair with the string of Latin characters
                      Ṛ   |   - Reverse (so we now have e.g. ["rk", 44032]

섹션 4.3 : 섹션 3의 출력에서 ​​이러한 라틴 문자 문자열을 기본 형태 블록의 유니 코드 코드 포인트로 바꿉니다.

ñ   | Call helper link 1 (effectively search and replace)
 ṣ0 | Split at the zeros introduced in section 4.2

섹션 4.4 : 각 형태 블록의 일부로 종성이 있는지 확인

                                        Ʋ | Following as a monad:
Ḋ                                         | - Remove the first sublist (which won’t contain a morphemic block; note this will be restored later)
                                     €    | - For each of the other lists Z returned by the split in section 4.3 (i.e. each will have a morphemic block at the beginning):
                                  Ʋ©?     |   - If the following is true (capturing its value in the register in the process) 
             Ḋ                            |     - Remove first item (i.e. the Unicode code point for the base morphemic block introduced in section 4.3)
              ;⁶                          |     - Append a space (avoids ending up with an empty list if there is nothing after the morphemic block code point)
                                          |       (Output from the above will be referred to as X below)
                                ¤         |       * Following as a nilad (call this Y):
                        ¢                 |         * Helper link 4
                         Ṫ                |         * Jongseong
                              Ʋ€          |         * For each Jongseong Latin list:
                          Ẉ               |           * Lengths of lists
                           Ṫ              |           * Tail (i.e. length of Latin character string)
                            ‘             |           * Increase by 1
                             ;            |           * Prepend this (e.g. [1, 1, "r"]
                     ¥Ƈ@                  |     - Filter Y using X from above and the following criteria
                Ṫ                         |       - Tail (i.e. the Latin characters for the relevant Jongseong
                 ⁼ṁ@¥                     |       - is equal to the beginning of X trimmed to match the relevant Jongseong (or extended but this doesn’t matter since no Jongseong are a double letter)
                                  Ḣ       |       - First matching Jongseong (which since they’re sorted by descending size order will prefer the longer one if there is a matching shorter one)
           Ɗ                              | - Then: do the following as a monad (note this is now using the list Z mentioned much earlier):
      Ɗ                                   |   - Following as a monad
 Ḣ                                        |     - Head (the Unicode code point of the base morphemic block)
  +®Ṫ¤                                    |     - Add the tail of the register (the position of the matched Jongsepng in the list of Jongseong)
       ;                                  |   - Concatenate to:
        ṫ®$                               |     - The rest of the list after removing the Latin characters representing the Jongseong
            ¹                             | - Else: leave the list untouched (no matching Jongseong)
                                       ṭ  | - Prepend:
                                        Ḣ |   - The first sublist from the split that was removed at the beginning of this subsection

섹션 5 : 한국어 문자와 일치하지만 형태소 블록의 일부가 아닌 나머지 라틴 문자 처리

F                   | Flatten
                ¤   | Following as a nilad
 2£                 | - Helper link 2 (Latin characters/pairs of characters in Unicode order of corresponding Korean character)
          $         | - Following as a monad
   ż     Ɗ          |   - zip with following as a monad
    J               |     - Sequence along helper link 2 (1..51)
     +⁽.[           |     - Add 12592
             $Þ     | - Sort using following as key
           Ẉ        |   - Lengths of lists
            Ṫ       |   - Tail (i.e. length of Latin string)
               Ṛ    | - Reverse
                 ñ  | Call helper link 1 (search Latin character strings and replace with Korean code points)
                  Ọ | Finally, convert all Unicode code points back to characters and implicitly output

1
출력이 잘못되었습니다 : 내가 넣었을 때 책나는 제외 cor했지만 그것을주었습니다 cBor. 그리고 그것은 변경되지 않습니다 c에 ㅊ. can로 변환해야 ㅊ무했지만로 변환되었습니다 c무. 또한 사양에 나타나지 않는 큰 문자를 제외하고는 용량이 줄어 들었지만 괜찮을 수 있습니다.
— LegenDUST

@LegenDUST c 문제가 해결되었습니다. 나는 A단일 문자의 두 번째 문자에 대한 자리 표시 자로 사용 되었으며 어떤 이유로 이후 문자 c가로 등장했습니다 B. 다른 문자의 소문자로의 변환은 가능하지만, 이미 어려운 과제에 불필요한 합병증처럼 느껴집니다.
— Nick Kennedy

나는 이것이 어렵다는 것을 이해한다. 따라서 새로운 규칙을 추가했습니다. 용량을 줄이면 5 바이트를 벌 수 있습니다. 그러나 이것은 괜찮습니다.
— LegenDUST

3

자바 스크립트 (Node.js를) , 587 582 575 569 557 554 550 549 바이트

tfw 당신은 그것을 몰랐다 string.charCodeAt() == string.charCodeAt(0).

s=>s.replace(eval(`/[ㄱ-힣]|${M="(h[kol]?|n[jpl]?|ml?|[bi-puyOP])"}|([${S="rRseEfaqQtTdwWczxvg"}])(${M}((s[wg]|f[raqtxvg]|qt|[${S}])(?!${M}))?)?/g`,L="r,R,rt,s,sw,sg,e,E,f,fr,fa,fq,ft,fx,fv,fg,a,q,Q,qt,t,T,d,w,W,c,z,x,v,g,k,o,i,O,j,p,u,P,h,hk,ho,hl,y,n,nj,np,nl,n,m,ml,l".split`,`,l=L.filter(x=>!/[EQW]/.test(x)),I="indexOf"),(a,E,A,B,C,D)=>a<"~"?E?X(E):A&&C?F(43193+S[I](A)*588+L[I](C)*28+l[I](D)):X(A)+X(C)+X(D):(b=a.charCodeAt()-44032)<0?L[b+31439]||a:S[b/588|0]+L[30+b/28%21|0]+["",...l][b%28],F=String.fromCharCode,X=n=>n?F(L[I](n)+12593):"")

온라인으로 사용해보십시오!

547 알파벳과 한국어 자모 이외의 문자는 무시할 수있는 경우

좋아, 나는 이것을 작성하기 위해 오랫동안 고투했지만, 이것이 효과가있다. 한국어 jamo / syllable은 너무 비싸서 (사용 당 3 바이트) 사용되지 않습니다. 정규 표현식에서 바이트를 저장하는 데 사용됩니다.

s=>                                                    // Main Function:
 s.replace(                                            //  Replace all convertible strings:
  eval(
   `/                                                  //   Matching this regex:
    [ㄱ-힣]                                             //   ($0) All Korean jamos and syllables
    |${M="(h[kol]?|n[jpl]?|ml?|[bi-puyOP])"}           //   ($1) Isolated jungseong codes
    |([${S="rRseEfaqQtTdwWczxvg"}])                    //   ($2) Choseong codes (also acts as lookup)
     (                                                 //   ($3) Jungseong and jongseong codes:
      ${M}                                             //   ($4)  Jungseong codes
      (                                                //   ($5)  Jongseong codes:
       (                                               //   ($6)
        s[wg]|f[raqtxvg]|qt                            //          Diagraphs unique to jongseongs
        |[${S}]                                        //          Or jamos usable as choseongs
       ) 
       (?!${M})                                        //         Not linked to the next jungseong
      )?                                               //        Optional to match codes w/o jongseong
     )?                                                //       Optional to match choseong-only codes
   /g`,                                                //   Match all
   L="(...LOOKUP TABLE...)".split`,`,                  //   Lookup table of codes in jamo order
   l=L.filter(x=>!/[EQW]/.test(x)),                    //   Jongseong lookup - only first half is used
   I="indexOf"                                         //   [String|Array].prototype.indexOf
  ),
  (a,E,A,B,C,D)=>                                      //   Using this function:
   a<"~"?                                              //    If the match is code (alphabets):
    E?                                                 //     If isolated jungseongs code:
     X(E)                                              //      Return corresponding jamo
    :A&&C?                                             //     Else if complete syllable code:
     F(43193+S[I](A)*588+L[I](C)*28+l[I](D))           //      Return the corresponding syllable
    :X(A)+X(C)+X(D)                                    //     Else return corresponding jamos joined
   :(b=a.charCodeAt()-44032)<0?                        //    Else if not syllable:
    L[b+31439]||a                                      //     Return code if jamo (if not, ignore)
   :S[b/588|0]+L[30+b/28%21|0]+["",...l][b%28],        //    Else return code for the syllable
  F=String.fromCharCode,                               //   String.fromCharCode
  X=n=>                                                //   Helper function to convert code to jamo
   n?                                                  //    If not undefined:
    F(L[I](n)+12593)                                   //     Return the corresponding jamo
   :""                                                 //    Else return empty string
 )

2

볼프람 언어 (티카) , (405) 401 400 바이트

c=CharacterRange
p=StringReplace
q=StringReverse
r=Reverse
t=Thread
j=Join
a=j[alphabet@"Korean",4520~c~4546]
x=j[#,r/@#]&@t[a->Characters@"rRseEfaqQtTdwWczxvgkoiOjpuPh"~j~StringSplit@"hk ho hl y n nj np nl b m ml l r R rt s sw sg e f fr fa fq ft fx fv fg a q qt t T d w c z x v g"]
y=t[""<>r@#&/@Tuples@TakeList[Insert[a,"",41]~p~x~p~x,{19,21,28}]->44032~c~55203]
f=q@p[q@#,#2]&
g=f[#,r/@y]~p~x~f~y&

온라인으로 사용해보십시오!

약간 골퍼

단지 대체 티카이를 테스트하려면 alphabet와 Alphabet; 그러나 TIO는 Wolfram Cloud를 지원하지 않으므로 Alphabet["Korean"]헤더에 정의 했습니다.

먼저 모든 한글 음절을 한글 알파벳으로 분해 한 다음 라틴어와 한글 문자를 바꾸고 음절을 재구성합니다.


1
TIO 대신 테스트 사례 input 2결과 . 동일 용액에 발생하지만 둘 다 이후에 일하는 및 jungseong하고, 나는 단지 초성 + jungseong + jongseong 또는 초성 + jungseong + 빈 결합 될 것이다 인상이었다. 왜 검증을 위해 OP를 요구 했다 . ㅑㅜㅔㅕㅅ 2ㅑㅞㅕㅅ 2ㅜㅔㅜㅔㅞ
— Kevin Cruijssen

@KevinCruijssen np (np)는 자체적으로 정성입니다
— Nick Kennedy

1
두 자음 또는 모음에는 제대로 작동하지 않는 것 같습니다. 예를 들어 fnpfa단일 문자 여야 뤪하지만 대신 다음과 같이 끝납니다.루ㅔㄹㅁ
— Nick Kennedy

수정 중입니다. 비용이 너무 많이 들지 않아야합니다.
— lirtosiast

2

Java 19, 1133 1126 1133 바이트

s->{String r="",k="ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ",K[]=k.split(" "),a="r R s e E f a q Q t T d w W c z x v g k o i O j p u P h hk ho hl y n nj np nl b m ml l r R rt s sw sg e f fr fa fq ft fx fv fg a q qt t T d w c z x v g";var A=java.util.Arrays.asList(a.split(" "));k=k.replace(" ","");int i,z,y,x=44032;for(var c:s.toCharArray())if(c>=x&c<55204){z=(i=c-x)%28;y=(i=(i-z)/28)%21;s=s.replace(c+r,r+K[0].charAt((i-y)/21)+K[1].charAt(y)+(z>0?K[2].charAt(z-1):r));}for(var c:s.split(r))r+=c.charAt(0)<33?c:(i=k.indexOf(c))<0?(i=A.indexOf(c))<0?c:k.charAt(i):A.get(i);for(i=r.length()-1;i-->0;r=z>0?r.substring(0,i)+(char)(K[0].indexOf(r.charAt(i))*588+K[1].indexOf(r.charAt(i+1))*28+((z=K[2].indexOf(r.charAt(i+2)))<0?0:z+1)+x)+r.substring(z<0?i+2:i+3):r)for(z=y=2;y-->0;)z&=K[y].contains(r.charAt(i+y)+"")?2:0;for(var p:"ㅗㅏㅘㅗㅐㅙㅗㅣㅚㅜㅓㅝㅜㅔㅞㅜㅣㅟㅡㅣㅢ".split("(?<=\\G...)"))r=r.replace(p.substring(0,2),p.substring(2));return r;}

-5 이상의 보너스 비용이 들기 ASDFGHJKLZXCVBNM때문에 대문자가있는 출력은 변경되지 않습니다 .toLowerCase().

유니 코드 값이 20,000을 초과하는 한국어 이외의 문자에 대한 버그 수정으로 +7 바이트를 반환 합니다.

온라인으로 사용해보십시오.

설명:

s->{                         // Method with String as both parameter and return-type
  String r="",               //  Result-String, starting empty
         k="ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ",
                             //  String containing the Korean characters
         K[]=k.split(" "),   //  Array containing the three character-categories
         a="r R s e E f a q Q t T d w W c z x v g k o i O j p u P h hk ho hl y n nj np nl b m ml l r R rt s sw sg e f fr fa fq ft fx fv fg a q qt t T d w c z x v g"; 
                             //  String containing the English characters
  var A=java.util.Arrays.asList(a.split(" "));
                             //  List containing the English character-groups
  k=k.replace(" ","");       //  Remove the spaces from the Korean String
  int i,z,y,                 //  Temp integers
      x=44032;               //  Integer for 0xAC00
  for(var c:s.toCharArray()) //  Loop over the characters of the input:
    if(c>=x&c<55204){        //   If the unicode value is in the range [44032,55203]
                             //   (so a Korean combination character):
      z=(i=c-x)%28;          //    Set `i` to this unicode value - 0xAC00,
                             //    And then `z` to `i` modulo-28
      y=(i=(i-z)/28)%21;     //    Then set `i` to `i`-`z` integer divided by 28
                             //    And then `y` to `i` modulo-21
      s=s.replace(c+r,       //    Replace the current non-Korean character with:
        r+K[0].charAt((i-y)/21)
                             //     The corresponding choseong
         +K[1].charAt(y)     //     Appended with jungseong
         +(z>0?K[2].charAt(z-1):r));}
                             //     Appended with jongseong if necessary
  for(var c:s.split(r))      //  Then loop over the characters of the modified String:
    r+=                      //   Append to the result-String:
       c.charAt(0)<33?       //    If the character is a space:
        c                    //     Simply append that space
       :(i=k.indexOf(c))<0?  //    Else-if the character is NOT a Korean character:
         (i=A.indexOf(c))<0? //     If the character is NOT in the English group List:
          c                  //      Simply append that character
         :                   //     Else:
          k.charAt(i)        //      Append the corresponding Korean character
       :                     //    Else:
        A.get(i);            //     Append the corresponding letter
  for(i=r.length()-1;i-->0   //  Then loop `i` in the range (result-length - 2, 0]:
      ;                      //    After every iteration:
       r=z>0?                //     If a group of Korean characters can be merged:
          r.substring(0,i)   //      Leave the leading part of the result unchanged
          +(char)(K[0].indexOf(r.charAt(i))
                             //      Get the index of the first Korean character,
                   *588      //      multiplied by 588
                  +K[1].indexOf(r.charAt(i+1))
                             //      Get the index of the second Korean character,
                   *28       //      multiplied by 28
                  +((z=K[2].indexOf(r.charAt(i+2)))
                             //      Get the index of the third character
                    <0?      //      And if it's a Korean character in the third group:
                      0:z+1) //       Add that index + 1
                  +x         //      And add 0xAC00
                 )           //      Then convert that integer to a character
          +r.substring(z<0?i+2:i+3) 
                             //      Leave the trailing part of the result unchanged as well
         :                   //     Else (these characters cannot be merged)
          r)                 //      Leave the result the same
     for(z=y=2;              //   Reset `z` to 2
         y-->0;)             //   Inner loop `y` in the range (2, 0]:
       z&=                   //    Bitwise-AND `z` with:
         K[y].contains(      //     If the `y`'th Korean group contains
           r.charAt(i+y)+"")?//     the (`i`+`y`)'th character of the result
          2                  //      Bitwise-AND `z` with 2
         :                   //     Else:
          0;                 //      Bitwise-AND `z` with 0
                             //   (If `z` is still 2 after this inner loop, it means
                             //    Korean characters can be merged)
  for(var p:"ㅗㅏㅘㅗㅐㅙㅗㅣㅚㅜㅓㅝㅜㅔㅞㅜㅣㅟㅡㅣㅢ".split("(?<=\\G...)"))
                             //  Loop over these Korean character per chunk of 3:
    r=r.replace(p.substring(0,2),
                             //   Replace the first 2 characters in this chunk
         p.substring(2));    //   With the third one in the result-String
  return r;}                 //  And finally return the result-String

1
그것들은 44032에서 55203입니다. 당신은 이미 시작 위치를 코딩했습니다. 끝은 단지44032 + 19×21×28 - 1
— 닉 케네디

지금은 잘 작동합니다. 내가 이미 당신을 공감했지만 생각하지 않았다고 생각했습니다.
— Nick Kennedy
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.