akela43

countMax

Apr 13th, 2020
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. def countMax(lst):
  2.     if len(lst) == 1:
  3.         return (lst[0],1)
  4.     else:
  5.         m, n0 = countMax(lst[1:]), lst[0]
  6.         if n0 > m[0]:
  7.             return (n0, 1 )
  8.         else:
  9.             return (m[0], m[1] + 1) if n0 == m[0] else m
  10.        
  11. import random
  12.  
  13. #n = int(input())
  14. #lst = []
  15. #while n != 0:
  16. #    lst.append(n)
  17. #    n = int(input())
  18.    
  19. for i in range(0,100):
  20.     n = random.randint(2, 30)
  21.     lst = [random.randint(-5,5) for _ in range(1, n)]
  22.     print (countMax(lst)[1], lst.count(max(lst)))
Advertisement
Add Comment
Please, Sign In to add comment