SHARE
TWEET

ECOO '19 R1 P2 - L-Systems Go

weCryOPEN Feb 26th, 2020 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. for _ in range(10):
  2.     r, t, a = input().split()
  3.     r = int(r)
  4.     t = int(t)
  5.    
  6.     # Key - C
  7.     # Value - S
  8.     rules = dict()
  9.    
  10.     length = 0
  11.     freq = dict()
  12.    
  13.     for c in a:
  14.         freq[c] = freq.get(c, 0) + 1
  15.    
  16.     for i in range(r):
  17.         # Record all the rules and their lengths in
  18.         # the rules dictionary.
  19.         c, s = input().split()
  20.         rules[c] = s
  21.    
  22.     for i in range(t):
  23.         # We only need to care about the first and last
  24.         # letters for each iteration. a[-1] returns the
  25.         # last letter.
  26.         if len(a) == 1:
  27.             a = rules[a]
  28.         else:
  29.             a = rules[a[0]][0] + rules[a[-1]][-1]
  30.        
  31.         for c, count in list(freq.items()):
  32.             freq[c] -= count
  33.             for x in rules[c]:
  34.                 freq[x] = freq.get(x, 0) + count
  35.            
  36.     print(a[0] + a[-1], sum(freq.values()))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top