Advertisement
Guest User

capacity1.py

a guest
Aug 5th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. elevations = input()
  2. elevations = [int(i) for i in elevations if i != ' ']
  3.  
  4. def transform(elevations):
  5.     landscape = ['' for i in range(max(elevations))]
  6.     for i in range(len(landscape)):
  7.         for k in elevations:
  8.             if len(landscape) - i > k:
  9.                 landscape[i] += ' '
  10.             else:
  11.                 landscape[i] += 'X'
  12.     return landscape
  13.  
  14. def capacity(landscape):
  15.     puddles = 0
  16.     for i in range(len(landscape)):
  17.         for k in range(len(landscape[i])//2):
  18.             puddle = 'X' + ' ' * (k+1) + 'X'
  19.             if landscape[i].find(puddle) != -1:
  20.                 puddles += k + 1 * landscape[i].count(puddle)
  21.             else:
  22.                 continue
  23.     return puddles
  24.  
  25. print(capacity(transform(elevations)))
  26.  
  27.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement