#K64452. Categorizing Words Based on Specific Conditions
Categorizing Words Based on Specific Conditions
Categorizing Words Based on Specific Conditions
You are given a list of words. For each word, you must determine whether it is a "FOUR" word or a "NOT FOUR" word. A word is defined to be a "FOUR" word if and only if it has exactly 4 characters and its first and last characters are identical. Otherwise, the word is classified as "NOT FOUR".
For example, given the word noon
, since it is 4 letters long and 'n' (the first letter) is the same as 'n' (the last letter), the word is classified as "FOUR". In contrast, the word tree
is not classified as "FOUR" because although it has 4 letters, its first and last letters differ. Your task is to read a list of words and output a JSON-formatted dictionary mapping each word to its classification.
The classification condition can be expressed mathematically as follows:
\( word \text{ is FOUR if } |word| = 4 \text{ and } word[0] = word[3] \).
inputFormat
The input is read from stdin and is formatted as follows:
- The first line contains a single integer \(N\) indicating the number of words.
- The second line contains \(N\) words separated by spaces.
outputFormat
Output to stdout a JSON string representing a dictionary. The dictionary should contain each input word as a key and its classification (either "FOUR" or "NOT FOUR") as the corresponding value.
## sample4
noon deed abba peep
{"noon": "FOUR", "deed": "FOUR", "abba": "FOUR", "peep": "FOUR"}