Skip to content

Instantly share code, notes, and snippets.

@whizzzkid
Last active February 13, 2017 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whizzzkid/3d97c31a9b8af70afaee8e998858cbcc to your computer and use it in GitHub Desktop.
Save whizzzkid/3d97c31a9b8af70afaee8e998858cbcc to your computer and use it in GitHub Desktop.
actions = int(raw_input())
def node():
return [0, {}]
contacts = node()
for a in xrange(actions):
action, word = map(str, raw_input().split())
cont = contacts
if action == 'add':
cont[0] += 1
for c in word:
if not cont[1].get(c):
cont[1][c] = node()
cont = cont[1].get(c)
cont[0] += 1
if action == 'find':
for c in word:
cont = cont[1].get(c)
if not cont:
break
print cont[0] if cont else 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment