Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import itertools
- import operator
- all_books = []
- class Library:
- def __init__(self, lib_array):
- self.count = lib_array[0]
- self.signup = lib_array[1]
- self.books_per_day = lib_array[2]
- self.all_books = lib_array[3]
- self.all_books = list(map(int, self.all_books))
- arr3 = []
- for value in self.all_books:
- arr3.append(all_books[value])
- precomputed_arr = [0]
- sorted_by_score = self.all_books.sort()
- for i in range(0, len(self.all_books), int(self.books_per_day)):
- result = list(map(int, self.all_books[i:(int(self.books_per_day) + i)]))
- result_sums = 0
- for j in range(i, (int(self.books_per_day) + i)):
- result_sums = result_sums + arr3[j]
- precomputed_arr.append(precomputed_arr[-1] + result_sums)
- self.precomputed_score = precomputed_arr
- def __repr__(self):
- return [self.count, self.signup, self.books_per_day, self.all_books, self.precomputed_score]
- def __repr__(self):
- return str([self.count, self.signup, self.books_per_day, self.all_books, self.precomputed_score])
- def read_library_data(filename):
- with open(filename, "r") as f:
- firstline = f.readline()
- general = firstline.split()
- books = general[0]
- libraries = general[1]
- days_for_scanning = general[2]
- book_scores = f.readline() #todo
- book_scores = book_scores.split()
- book_scores = list(map(int, book_scores))
- for book in book_scores:
- all_books.append(int(book))
- library_array = []
- for lib in f:
- lib_array = lib.split()
- books_in_lib = next(f)
- books_in_library = books_in_lib.split()
- lib_array.append(books_in_library)
- library_array.append(Library(lib_array))
- print Library(lib_array)
- # print library_array
- with open(filename + "results", w) as w:
- if __name__ == "__main__":
- read_library_data(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement