Dokkaebi-bul
Time limit1sMemory limit1024 MB
Given a string typed in English mode on a 2-set keyboard, count how many times the Dokkaebi-bul phenomenon occurs when it is typed in Korean mode.
- Level
Medium4 of 10
- Topics
- String, Simulation, Implementation
- Solved
- No attempts yet
Problem

When you type Korean on a 2-set keyboard, you can run into an unusual effect called the Dokkaebi-bul phenomenon. Other input methods rarely show it. For example, follow each keystroke while typing 서강대학교:
ㅅ
서
석
서가
서강
서강ㄷ
서강대
서강댛
서강대하
서강대학
서강대학ㄱ
서강대학교
When '석' changes to '서가', the consonant that will become the initial of the next syllable attaches first to the final position of the syllable being typed. This is called the Dokkaebi-bul phenomenon.
Typing 서강대학교 causes the Dokkaebi-bul phenomenon twice. Here are more examples.
- 이보세요: ('입' to '이보'), ('이봇' to '이보세'), ('이보셍' to '이보세요')
- 코딩하기 싫다: ('콛' to '코딩'), ('코딩학' to '코딩하기')
- 마춤뻐비 틀려써요: ('맟' to '마추'), ('마춤뻡' to '마춤뻐비'), ('마춤뻐비 틀렸' to '마춤뻐비 틀려써'), ('마춤뻐비 틀려썽' to '마춤뻐비 틀려써요')
Given a string, count how many Dokkaebi-bul phenomena occur when you type that string on the keyboard.
Input
The first line contains a Korean string made of spaces and precomposed Hangul syllables, written as the keys typed in English input mode. The length of the string is at least 1 and at most .
Output
Print the number of Dokkaebi-bul phenomena that occur when the given string is typed in Korean input mode.
Hint
Double consonants ㄲ, ㄸ, ㅃ, ㅆ, ㅉ correspond to R, E, Q, T, W, respectively, and cannot be typed the way rr, ee, qq, tt, ww would be.
There are 19 initial consonants, 21 vowels, and 27 final consonants.
Refer to the 2-set keyboard image above for the key layout. (Korean keys follow 2-set, English keys follow QWERTY.)