Hangul 2
Time limit1sMemory limit256 MB
Given one Hangul syllable, compute its one-based index in the ordered list of 11172 syllables.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Every Hangul syllable is built from an initial consonant, a vowel, and a final consonant, written together as one character.
There are 19 initial consonants: ㄱ, ㄲ, ㄴ, ㄷ, ㄸ, ㄹ, ㅁ, ㅂ, ㅃ, ㅅ, ㅆ, ㅇ, ㅈ, ㅉ, ㅊ, ㅋ, ㅌ, ㅍ, ㅎ. There are 21 vowels: ㅏ, ㅐ, ㅑ, ㅒ, ㅓ, ㅔ, ㅕ, ㅖ, ㅗ, ㅘ, ㅙ, ㅚ, ㅛ, ㅜ, ㅝ, ㅞ, ㅟ, ㅠ, ㅡ, ㅢ, ㅣ. There are 28 final consonants, counting the empty one: none, ㄱ, ㄲ, ㄳ, ㄴ, ㄵ, ㄶ, ㄷ, ㄹ, ㄺ, ㄻ, ㄼ, ㄽ, ㄾ, ㄿ, ㅀ, ㅁ, ㅂ, ㅄ, ㅅ, ㅆ, ㅇ, ㅈ, ㅊ, ㅋ, ㅌ, ㅍ, ㅎ.
The syllables are listed so that the final consonant changes fastest. Once the final consonants wrap around, the vowel advances by one, and once the vowels wrap around, the initial consonant advances by one. So the first syllable is "가", made of the initial consonant ㄱ, the vowel ㅏ, and no final consonant, and the second syllable is "각", made of ㄱ, ㅏ, and the final consonant ㄱ. The last syllable is "힣", made of ㅎ, ㅣ, and ㅎ.
Combining an initial consonant, a vowel, and a final consonant gives syllables in total.
Given one Hangul syllable, write a program that finds its position in this list.
Input
The first line contains one character. It is a Hangul syllable encoded in UTF-8, and it can be built by the method described above.
Output
Print the position of the given syllable.