Under construction

Still being built. Things may change

YAML

Time limit2sMemory limit512 MB

Summary
Parse a small YAML-like nested mapping from indentation, then walk a dotted query path and report whether the target is a string, object, or missing.
Level

Medium4 of 10

Topics
String, Implementation, Stack, Hash map
Solved
No attempts yet

Problem

YAML (YAML Ain't Markup Language) is a format for representing objects as strings.

Given an object written in a subset of YAML and a query that specifies a property, output the value of the specified property.

Subset of YAML

The subset of YAML follows the grammar expressed by the following extended BNF notation.

yaml: mapping(0)
mapping(n): mapping-item(n) | mapping-item(n) mapping(n)
mapping-item(n): indent(n) key ':' ' ' string '\n'
                 | indent(n) key ':' '\n' mapping(m) (where m>n)
key: [a-z0-9]+ (a string of one or more lowercase letters or digits)
string: [a-z0-9 ]+ (a string of one or more lowercase letters, digits, or spaces)
indent(0): "" (the empty string)
indent(n+1): ' ' indent(n) (a string of n+1 spaces)

'\n' represents a newline character.

mapping(n) represents an object, and each mapping-item(n) contained in mapping(n) represents a property contained in that object.

mapping-item(n): indent(n) key ':' ' ' string '\n' indicates that the value of the property named key is the string represented by string.

mapping-item(n): indent(n) key ':' '\n' mapping(m) indicates that the value of the property named key is the object represented by mapping(m).

No object contains two or more properties with the same key.

Format of the query that specifies a property

The query that specifies a property is given in the form where '.' and key alternate, such as

.key_1.key_2(..omitted..).key_n

which means "the property named keyn of the object that is the value of the property named key2 of the object that is the value of the property named key1 of the object given by yaml, (..omitted..)".

For some i (1 ≤ i ≤ n - 1), if the value of the property represented by .key_1.key_2.(..omitted..).key_i is not an object, or is an object but does not contain a property named key_i+1, then the property represented by .key_1.key_2(..omitted..).key_n is considered not to exist.

Input

.key_1.key_2(...).key_n
yaml
  • 1 ≤ n ≤ 20
  • The total number of characters in the input is ≤ 50,000

Output

Output the value of the property on a single line.

If the specified property does not exist, output no such property. If the value of the property is an object, output object. If the value of the property is a string, output string "<contents of the string>".

Examples5

  1. Example 1

    Input
    .tweets.1
    name: shimeji
    id: shimejitan
    tweets:
      1: shimejilove
      2: azupero
    
    Expected output
    string "shimejilove"
    
  2. Example 2

    Input
    .a
    a: sample case
    
    Expected output
    string "sample case"
    
  3. Example 3

    Input
    .my.obj
    my:
     str: string value
     obj:
        a: a
        b: b
        c: c
    
    Expected output
    object
    
  4. Example 4

    Input
    .str.inner
    str: inner
    
    Expected output
    no such property
    
  5. Example 5

    Input
    .no.such.property
    object:
        prop1: str
        prop2: str
    
    Expected output
    no such property