Arsylk

Narkoman in Resonance

Oct 23rd, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def file_to_array(filename):
  2.     file = open(filename, "r")
  3.     file_content = file.read();
  4.     file.close();
  5.  
  6.     return list(map(int, file_content.strip().split("\n")))
  7.  
  8.  
  9. def get_max_sum(arr):
  10.     max = arr[0]
  11.     for i in range(len(arr)-1):
  12.         s = arr[i] + arr[i+1]
  13.         if s > max:
  14.             max = s
  15.     if arr[-1] > max:
  16.         max = arr[-1]
  17.     return max
  18.  
  19.  
  20. def get_most_popular(arr):
  21.    
  22.     return max(arr, key=arr.count)
  23.  
  24.    
  25.  
  26. print("----------------")
  27. for file in ["dane5-1.txt", "dane5-2.txt", "dane5-3.txt"]:
  28.     print(file)
  29.     arr = file_to_array(file)
  30.     print("Max sum: {:d}".format(get_max_sum(arr)))
  31.     print("Popular: {:d}".format(get_most_popular(arr)));
  32.     print("----------------")
Advertisement
Add Comment
Please, Sign In to add comment