#K61752. Reverse Alphabetic Strings
Reverse Alphabetic Strings
Reverse Alphabetic Strings
You are given a list represented as a JSON array read from standard input. Your task is to process the list according to the following rules:
- If the list is empty, print
The list is empty.
- If any item in the list is not of type string, print
The list contains non-string items.
- If any string contains non‐alphabetic characters (i.e. it does not match the regular expression \( ^[a-zA-Z]+$ \)), then print an error message in the following format:
There {is/are} N invalid {entry/entries}: [list]
Useisalpha()
(or its equivalent) to check whether a string is alphabetic. For pluralization, use "are" and "entries" when applicable. - If all strings are valid, output the reversed list in JSON array format.
Note: The checking of alphabetic characters is equivalent to testing if a string \(s\) satisfies \(s.isalpha()\). Ensure that your output exactly matches the described messages.
inputFormat
The input consists of a single line containing a JSON array. The array may contain elements that are strings, numbers, booleans, etc. For example:
["apple", "banana", "cherry", "date"]
All input should be read from STDIN.
outputFormat
If the input list is valid (non-empty, all items are strings, and all strings contain only alphabetic characters), output the reversed list in JSON array format.
Otherwise, output one of the following error messages:
The list is empty.
The list contains non-string items.
There {is/are} N invalid {entry/entries}: [list]
["apple", "banana", "cherry", "date"]
["date", "cherry", "banana", "apple"]