Advertisement
weCryOPEN

ECOO '19 R1 P2 - L-Systems Go

Feb 26th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  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()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement