#C12232. String Parsing Problem

    ID: 41637 Type: Default 1000ms 256MiB

String Parsing Problem

String Parsing Problem

You are given a string s that may contain letters, digits, spaces, and special characters. Your task is to parse the string and segregate it into three parts:

  • digits: A list of contiguous digit sequences (i.e. sequences containing characters 0-9).
  • words: A list of contiguous alphabetic sequences (both uppercase and lowercase letters A-Z and a-z).
  • special_chars: A list of all characters that are neither alphanumeric nor whitespace. Each special character should be treated as an individual entry.

In mathematical terms, if we denote s as the input string, then the output is a dictionary:

\[ {\text{digits}: D,\quad \text{words}: W,\quad \text{special\_chars}: S} \]

where:

  • \( D = \{d_i\,|\, d_i \text{ is a maximal substring of consecutive digits in } s\}\)
  • \( W = \{w_i\,|\, w_i \text{ is a maximal substring of consecutive letters in } s\}\)
  • \( S = \{c\,|\, c \text{ is any character in } s \text{ and } c \notin \{0-9, A-Z, a-z, \text{whitespace}\}\}\)

Your solution should read the input from standard input (stdin) and output the resulting dictionary in JSON format to standard output (stdout).

inputFormat

The input consists of a single line string s. This string may contain spaces, digits, letters, and special characters.

outputFormat

The output should be a JSON formatted dictionary with three keys: digits, words, and special_chars. Each key maps to a list of strings as described in the problem statement.

## sample
abc 123 !@#
{"digits": ["123"], "words": ["abc"], "special_chars": ["!", "@", "#"]}