-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubs.py
executable file
·37 lines (28 loc) · 867 Bytes
/
subs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /usr/bin/python3
import sys
import argparse
import signal
import functools
import collections
def main(args):
string = sys.stdin.readline().strip()
pattern = sys.stdin.readline().strip()
# NOTE: obviously, not the fastest algorithm
# a suffix array (or a suffix tree, or something) would be faster for
# real data
#
locations = []
for i in range(len(string) - len(pattern)):
if string[i:].startswith(pattern):
locations.append(i+1)
print(*locations)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='description',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
args = parser.parse_args()
try:
main(args)
except BrokenPipeError:
sys.exit(128 + signal.SIGPIPE)
except KeyboardInterrupt:
sys.exit(128 + signal.SIGINT)