Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. a=input('Введите строку: ')
  2. max=-1
  3. for i in range(len(a)):
  4. counter=0
  5. count1=0
  6. count2=0
  7. count3=0
  8. for j in range(i,len(a)):
  9. if a[j]=='(':
  10. count1+=1
  11. if a[j]=='[':
  12. count2+=1
  13. if a[j]=='{':
  14. count3+=1
  15. if a[j]==')':
  16. count1-=1
  17. if a[j]==']':
  18. count2-=1
  19. if a[j]=='}':
  20. count3-=1
  21. counter+=1
  22. if count1<0 or count2<0 or count3<0:
  23. break
  24. if count1==0 and count2==0 and count3==0 and counter>max:
  25. max=counter
  26. start=i+1
  27. end=j+1
  28.  
  29. print('Длина: ',max,'Начало: ',start,'Конец: ',end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement