Created
September 6, 2010 15:55
-
-
Save anonymous/567181 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
from sys import stdin | |
__author__="Jonas Svarvaa" | |
__date__ ="$06.sep.2010 12:39:53$" | |
def parse_input(): | |
words = {} | |
pos = 0 | |
for s in stdin.readline().split(): | |
try: | |
words[s].append(pos) | |
except: | |
words[s]=[pos] | |
pos += len(s) + 1 | |
print words | |
for s in stdin: | |
s = s.strip() | |
if s in words: | |
print s+": "+" ".join(map(str, words[s])) | |
else: | |
print s+": "+str(mypos(s, 0, words)) | |
def mypos(needle, index, nodes): | |
if "?" in needle: | |
c = needle.count("?") | |
pos = 0 | |
w = [] | |
for c2 in range(c): | |
pos += needle[pos:].find("?")+1 | |
w.append(pos-1) | |
print w | |
else: | |
return "" | |
if __name__ == "__main__": | |
parse_input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment