Embercode
✕
TriesCoding problems

Tries: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 8 solved

  • A school library keeps a list of book titles, one lowercase word per book. The search box shows, for each thing a student types, how many different books start with those letters. A title that was entered twice still counts once.

    Read the list, then read each query. For each query, print how many different titles start with it.

    **Constraints:** 1 <= n <= 100000 titles and 1 <= q <= 100000 queries. Titles have 1 to 20 letters a to z. Queries have 1 to 10 letters a to z.

    Input. First line n. Next n lines: one title each. Then a line with q, followed by q lines, one query each.

    Output. One line per query: the number of different titles that start with that query.

    Example 1 input

    4
    car
    card
    car
    dog
    3
    ca
    d
    x
    

    Output

    2
    1
    0
    

    Example 2 input

    3
    book
    book
    book
    2
    b
    bookshelf
    

    Output

    1
    0