Embercode
✕
Tries (C++)Coding problems

Tries (C++): coding problems

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

0 of 7 solved

  • A spell checker keeps a long list of words. When the user types some letters, the checker needs to know how many words in the list begin with those letters. A word listed twice counts twice.

    Read the list, then answer each query with one number.

    Work through the examples first. Your program must match the output exactly.

    Input. The first line holds n, the number of words (1 to 100000). The next n lines each hold one word of lowercase letters a to z, 1 to 20 letters long. The next line holds q, the number of queries (1 to 100000). The last q lines each hold one prefix of lowercase letters, 1 to 20 letters long.

    Output. For each query, one line with the number of words in the list that start with that prefix.

    Example 1 input

    4
    car
    card
    care
    dog
    3
    ca
    do
    x
    

    Output

    3
    1
    0
    

    Example 2 input

    3
    ab
    ab
    aba
    2
    a
    ab
    

    Output

    3
    3