Urdu orthography verification
Time limit1sMemory limit256 MB
Check whether each encoded Urdu letter uses the detached, initial, medial or final shape required by its position and the two special vowels.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Urdu is written in the Nastaleeq or Naskh styles, from right to left and top to bottom. In these styles the shape of a letter depends on where that letter sits inside the word.
Every letter has a detached shape used on its own, plus up to three more shapes: initial, medial and final. Take the Urdu word for "picture", transliterated as tasviir. Read right to left, its letters are ta, s, vaow, cchoTi yay, ray. The first letter, ta, starts the word, so it takes its initial shape. The second letter, s, sits between two consonants, so it takes its medial shape, and the third letter, vaow, takes its medial shape for the same reason. The fourth letter, cchoTi yay, is preceded by vaow, one of the two special vowels of Urdu. alif and vaow are special because the letter right after them must be written in its initial shape. So cchoTi yay takes its initial shape even though it does not start the word. The last letter, ray, ends the word, so it takes its final shape.
Given a sequence of letters, each in some shape, decide whether the word is written correctly.
For this problem the 38 letters of the alphabet are numbered through . The first letter is , the second is , and the last is . The four shapes are encoded as detached , initial , medial and final . A letter in a given shape is written as a single value: multiply the letter number by and add the shape code.
The special vowels are letter numbers and , whatever shape those two letters themselves are written in. In a word of length , the shape required for the -th letter () comes from the first matching condition below, read top to bottom.
- If , the letter is detached.
- If and the preceding letter is a special vowel, the letter is detached.
- If and the preceding letter is not a special vowel, the letter is final.
- If , or the preceding letter is a special vowel, the letter is initial.
- Otherwise the letter is medial.
The word is correct when every letter is written in the shape it requires.
Input
The first line holds the number of test cases (). Each of the next lines holds a word length () followed by the encoded values of that word, separated by spaces. An encoded value is built as described above, so it is between and .
Output
For each test case print one line. Print Case #n: Yes if the word uses the required shapes, and Case #n: No otherwise. Here is the test case number, counting from .