#C170. String Information Dictionary

    ID: 44934 Type: Default 1000ms 256MiB

String Information Dictionary

String Information Dictionary

Given a list of elements in JSON format, extract each element which is a valid string at the top level, and create a dictionary where each key is the string and its value is a dictionary with two keys: \(length\) and \(vowels\). Here, \(length\) denotes the number of characters in the string, and \(vowels\) denotes the number of vowels (i.e. a, e, i, o, u regardless of case) that appear in the string.

The program should ignore any non-string elements, including strings that are nested inside other arrays or objects. If the input is invalid, the program should output an empty dictionary.

inputFormat

The input consists of a single line containing a JSON array. The array may include elements of various types. Only the elements that are strings at the top level should be processed.

For example:

["hello", "world", 42, ["nested", "array"], "test"]

outputFormat

The output should be a JSON object (dictionary) where each key is one of the valid string elements from the input array. The corresponding value is an object with two properties:

  • \(length\): the total number of characters in the string,
  • \(vowels\): the total number of vowels (a, e, i, o, u, case-insensitive) in the string.

For example:

{"hello":{"length":5,"vowels":2},"world":{"length":5,"vowels":1},"test":{"length":4,"vowels":1}}
## sample
["hello", "world", "example", "test", 42, "strings", ["list", "inside"], "another"]
{"hello":{"length":5,"vowels":2},"world":{"length":5,"vowels":1},"example":{"length":7,"vowels":3},"test":{"length":4,"vowels":1},"strings":{"length":7,"vowels":1},"another":{"length":7,"vowels":3}}