Skip to content

Instantly share code, notes, and snippets.

@fforbeck
Created June 6, 2012 17:02
Show Gist options
  • Save fforbeck/2883307 to your computer and use it in GitHub Desktop.
Save fforbeck/2883307 to your computer and use it in GitHub Desktop.
parser
import re
class InputScanner(object):
def __init__(self, filename, parse_function):
with open(filename) as f:
self.reversed_lines = list(reversed(f.read().split('\n')))
self.case_count = 0
self.total_cases = self.next_int()
self.parse_function = parse_function
def __iter__(self):
for i in range(self.total_cases):
yield self.next_case()
def next_int(self):
return int(self.reversed_lines.pop())
def next_line(self):
return self.reversed_lines.pop()
def next_matrix(self):
(h, w) = map(int, self.next_line().split())
return tuple(tuple(self.next_line()) for i in range(h))
def next_case(self):
p = self.parse_function(self)
self.case_count += 1
return p
class Solver(object):
def __init__(self, solver_function, input_scanner, out=None):
self.solver_function = solver_function
self.out = out
self.input_scanner = input_scanner
def solve(self):
for case in iter(self.input_scanner):
print >> self.out, 'Case #%s: %s' % (self.input_scanner.case_count,
self.solver_function(case))
def main(input_filename, out=None):
input_scanner = InputScanner(input_filename, parse_function)
Solver(solver_function, input_scanner, out).solve()
#impl
def parse_function(scanner):
class_count = scanner.next_int()
r = [map(int, scanner.next_line().split()[1:])
for i in range(class_count)]
return [[i - 1 for i in x] for x in r]
def solver_function(case):
return 'No'
if __name__ == '__main__':
main('input00.txt')
with open('small.out', 'w') as out: main('input00.txt', out)
print 'Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment