From 1f06cc322606e86918fefa1f707b54264e9ce0a9 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sun, 6 Nov 2016 21:53:13 +0700 Subject: Add others/dict --- others/dict/dict.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 others/dict/dict.py (limited to 'others/dict/dict.py') 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)) -- cgit 1.4.1