nq1s788

24 с арифм выражением

May 9th, 2026
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. #https://inf-ege.sdamgia.ru/problem?id=78049
  2. s = open('24_78049.txt').readline()
  3. s = s.replace('6', '!')
  4. s = s.replace('7', '!')
  5. s = s.replace('8', '!')
  6. s = s.replace('9', '!')
  7. s = s.split('!')
  8. answ = 0
  9. for e in s:
  10.     for l in range(len(e)):
  11.         for r in range(l, len(e)):
  12.             S = e[l:r+1]
  13.             if (S[0] != '-') and ('--' not in S) and ('**' not in S) and ('*-' not in S):
  14.                 try:
  15.                     eval(S)
  16.                 except Exception:
  17.                     pass #ничего не делать
  18.                 else:
  19.                     if len(S) > answ:
  20.                         answ = len(S)
  21. print(answ)
Advertisement
Add Comment
Please, Sign In to add comment