Advertisement
jootiee

Untitled

Feb 9th, 2022
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. file = "Задача_3__fz2g (1).txt"
  2.  
  3. with open(file, "r") as f:
  4.     data = f.read()
  5.  
  6. sum_ = 0
  7.  
  8. counted = False
  9. for i in range(1, len(data)):
  10.     if data[i] == data[i - 1]:
  11.         if counted:
  12.             counted = False
  13.             continue
  14.         else:
  15.             sum_ += int(data[i] + data[i - 1])
  16.             counted = True
  17.     else:
  18.         if counted:
  19.             counted = False
  20.  
  21. print(sum_)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement