Advertisement
Kwwiker

Код с разбора демо

Aug 31st, 2021
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. # Задача 17 способ 1
  2. tf = open('17.txt')
  3. maxi = float('-inf')
  4. count = 0
  5. prev_x = int(tf.readline())
  6. for x in tf:
  7.     x = int(x)
  8.     pair = prev_x + x
  9.     if prev_x % 3 == 0 or x % 3 == 0:
  10.         count += 1
  11.         maxi = max(pair, maxi)
  12.     prev_x = x
  13. print(count, maxi)
  14.  
  15. # Задача 17 способ 2
  16. a = [int(x) for x in open('17.txt')]
  17. count = 0
  18. maxi = -100000
  19. for i in range(1, len(a)):
  20.     if a[i - 1] % 3 == 0 or a[i] % 3 == 0:
  21.         count += 1
  22.         maxi = max([a[i - 1], a[i], maxi])
  23. print(count, maxi)
  24.  
  25. # Задача 24
  26. tf = open('24.txt')
  27. s = tf.readline()
  28. res = s[0]
  29. maxi = float('-inf')
  30. for i in range(1, len(s)):
  31.     if s[i - 1] + s[i] != 'PP':
  32.         res += s[i]
  33.         maxi = max(maxi, len(res))
  34.     else:
  35.         res = s[i]
  36. print(maxi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement