-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCC'07S2-Boxes.py
70 lines (59 loc) · 1.35 KB
/
CCC'07S2-Boxes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#CCC '07 S2 - Boxes
loops = int(input())
boxes = []
output = []
box_fit = False
def fits(item,box):
'''
Given dimensions of an item checks if it fits in a box of given dimensions
param: list
return: list
'''
for checks in range(3):
if max(item) > max(box):
return False
else:
item.remove(max(item))
box.remove(max(box))
return True
def vol(box):
'''
With given dimensions, calculates the volume
param: list
return: Integer
'''
total = 1
for dim in box:
total *= dim
return total
for loop in range(loops):
dimen = input()
boxes.append(dimen.split(" "))
for row in range(len(boxes)):
for col in range(3):
boxes[row][col] = int(boxes[row][col])
#oder boxes smallest to biggest
for loops in range(len(boxes)):
for box in range(len(boxes)-1):
if vol(boxes[box]) > vol(boxes[box+1]):
temp = boxes[box]
boxes[box] = boxes[box+1]
boxes[box+1] = temp
num_items = int(input())
for loops in range(num_items):
dimen = input()
item = dimen.split(" ")
for index in range(3):
item[index] = int(item[index])
for box in boxes:
if fits(item.copy(),box.copy()):
output.append(vol(box))
box_fit = True
break
else:
continue
if not(box_fit):
output.append("Item does not fit.")
box_fit = False
for item in output:
print(item)