68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
import random
|
|
import sys
|
|
|
|
|
|
class Cache:
|
|
def __init__(self, cpst1, cpst2):
|
|
self.cpst1 = cpst1
|
|
self.cpst2 = cpst2
|
|
|
|
self.list1 = []
|
|
self.list2 = []
|
|
|
|
def put_page(self, id:int):
|
|
if(id in self.list1):
|
|
return 0 #tic
|
|
elif (id in self.list2):
|
|
self.list2.remove(id) #tic
|
|
if(len(self.list1) < self.cpst1):
|
|
self.list1.insert(0, id)
|
|
else:
|
|
self.list1.pop(-1)
|
|
self.list1.insert(0, id)
|
|
|
|
elif (len(self.list2) < self.cpst2):
|
|
self.list2.insert(0, id)
|
|
|
|
return 0
|
|
else:
|
|
self.list2.pop(-1)
|
|
self.list2.insert(0, id)
|
|
|
|
def ret_cache(self):
|
|
return self.list1 + self.list2
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
number_of_test = int(input())
|
|
|
|
with open('pytests.txt', 'w+') as file:
|
|
|
|
for i in range(number_of_test):
|
|
vect = []
|
|
szq1 = random.randint(5, 10)
|
|
szq2 = random.randint(5, 10)
|
|
num_of_requests = (random.randint(1, 100))
|
|
|
|
cache = Cache(szq1, szq2)
|
|
|
|
vect.append(szq1)
|
|
vect.append(szq2)
|
|
vect.append(num_of_requests)
|
|
|
|
for j in range(num_of_requests):
|
|
id = random.randint(0, 100)
|
|
|
|
vect.append(id)
|
|
cache.put_page(id)
|
|
|
|
file.write(str(vect)[1:-1].replace(", ", " "))
|
|
file.write('\n')
|
|
|
|
file.write(str(cache.ret_cache())[1:-1].replace(", ", " "))
|
|
file.write('\n')
|
|
|