diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2016-11-06 21:53:13 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2016-11-06 21:53:13 +0700 |
commit | 1f06cc322606e86918fefa1f707b54264e9ce0a9 (patch) | |
tree | c8296702752782e04cd26669e0c35dba6949f439 /others/dict/dict.py | |
parent | b4b3cebf0ee4a22e4950f9c35cb7ef5e62be4103 (diff) | |
download | cp-1f06cc322606e86918fefa1f707b54264e9ce0a9.tar.gz |
Add others/dict
Diffstat (limited to 'others/dict/dict.py')
-rwxr-xr-x | others/dict/dict.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/others/dict/dict.py b/others/dict/dict.py new file mode 100755 index 0000000..59724cd --- /dev/null +++ b/others/dict/dict.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +from bisect import bisect_left as bisect + +words = [] + + +with open('dict.inp') as fi, open('dict.out', 'w') as fo: + for _ in range(int(fi.readline())): + w = fi.readline().strip() + i = bisect(words, w) + if i == len(words) or w != words[i]: + words.insert(i, w) + + for _ in range(int(fi.readline())): + s = fi.readline().strip() + i = bisect(words, s) + count = 0 + while i + count < len(words) and words[i + count].startswith(s): + count += 1 + fo.write("{}\n".format(count)) |