Advertisement
VladimirKostovsky

Monty Python on Friday (part III)

Jun 2nd, 2022
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. count = 0
  2. count_max = 0
  3. first_index_max = 0
  4. last_index_max = 0
  5. with open('input.txt') as f:
  6.     text = f.read()
  7.     l = [x for x in text]
  8.     for i in range(len(text)):
  9.         if text[i] == '(':
  10.             count += 1
  11.         if text[i] == ')':
  12.             if count > 0:
  13.                 count -= 1
  14.         if count_max < count:
  15.             count_max = count
  16.             first_index_max = i
  17.         if count_max - 1 == count:
  18.             last_index_max = i
  19.  
  20.     print(*text)
  21.     print("Максимальное колчество открытых скобок: ", count_max)
  22.     print(text[first_index_max+1:last_index_max])
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement