Advertisement
Guest User

Untitled

a guest
Nov 18th, 2011
1,673
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from optparse import OptionParser
  2. from collections import defaultdict
  3.  
  4. def run(inputWord):
  5.     a, states = open("avtomat.txt") ,defaultdict(list)
  6.     state, final= a.readline().split()[1:],a.readline().split()[1:]
  7.     [states[(i.split()[0], i.split()[1])].append(i.split()[3]) for i in a]
  8.     for letter in inputWord:
  9.         state = [st for s in state for st in states[(s,letter)]]
  10.     return any(i in state for i in final)
  11.  
  12. print [(b,"YES") if run(b) else (b,"NO") for b in OptionParser().parse_args()[1]]
  13.  
  14. # avtomat.txt:
  15. # init: q0
  16. # final: q2 q3
  17. # q0 a -> q1
  18. # q0 b -> q3
  19. # q1 a -> q1
  20. # q1 b -> q2
  21. # q2 a -> q2
  22. # q2 b -> q2
  23.  
  24.  
Advertisement
RAW Paste Data Copied
Advertisement