Last active
February 13, 2017 05:20
-
-
Save whizzzkid/3d97c31a9b8af70afaee8e998858cbcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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