From 7c9b47ab9149d292d5493c865dfb8742a7450472 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Tue, 10 Jan 2017 21:30:06 +0700 Subject: others/other: Add {bin,game}.pas and move others/dict here --- others/other/dict.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 others/other/dict.py (limited to 'others/other/dict.py') diff --git a/others/other/dict.py b/others/other/dict.py new file mode 100755 index 0000000..76b8414 --- /dev/null +++ b/others/other/dict.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +from itertools import islice +from bisect import bisect_left as bisect + + +with open('dict.inp') as fi, open('dict.out', 'w') as fo: + words = list(islice(fi, int(fi.readline()))) + words.sort() + + 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