Advertisement
Korotkodul

N1_v2

Apr 27th, 2023
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. s=''
  2. with open('f.txt') as f:
  3.     s = f.readline()
  4.  
  5. ans = 0
  6. fin = 0
  7. i = 0
  8.  
  9. s = s.replace('R', 'Q')
  10. s = s.replace('S', 'Q')
  11.  
  12. def f(l):
  13.     global i
  14.     while i + 1 < len(s):
  15.         #print("i = ", i)
  16.         if s[i] + s[i + 1] == 'QQ':
  17.             #print("A")
  18.             return l
  19.         i += 1
  20.         l += 1
  21.         if i + 1 == len(s):
  22.             #print("B")
  23.             return l
  24.    
  25.  
  26.  
  27. while i + 1 < len(s):
  28.     #print("i = ", i)
  29.     if s[i] + s[i + 1] == 'QQ':
  30.         i += 1
  31.         k = f(1)
  32.         #print("k = ", k)
  33.         if k > ans:
  34.             ans = k
  35.             fin = i
  36.  
  37.     i += 1
  38.    
  39. print(ans)
  40. print(fin)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement