-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
113 lines (104 loc) · 3.36 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
number_of_days = int(input())
class FatEmpty(Exception):
pass
fats = []
carbs = []
fibers=[]
first_dish = ''
first_fiber = 0
ingredient_counter=1
for ingredient in input().split():
#first split ingredients into respective categories with ingredient_counter representing the timestamp
if ingredient.startswith("FAT"):
ingredient_counter=ingredient_counter+1
fats.append(ingredient_counter)
elif ingredient.startswith("CARB"):
ingredient_counter=ingredient_counter+1
carbs.append(ingredient_counter)
elif ingredient.startswith("FIBER"):
ingredient_counter=ingredient_counter+1
fibers.append(ingredient_counter)
#check lengths
if first_dish == "":
if len(fats)+len(fibers) >= 4 and len(fats) >= 2:
fats.pop(0)
fats.pop(0)
for i in range(2):
try:
if fats[0] < fibers[0]:
fats.pop(0)
else:
fibers.pop(0)
except:#list index out of range
if fats:
fats.pop(0)
else:
fibers.pop(0)
first_dish = 'X'
print('X', end='')
elif len(carbs) >= 1 and len(fibers) >= 1 and (len(fibers)+len(carbs) >= 4):
carbs.pop(0)
fibers.pop(0)
#pop the necessary ingredients
#decide on third and fourth ingredients
for i in range(2):
try:
if carbs[0] < fibers[0]:
carbs.pop(0)
else:
fibers.pop(0)
except:
if carbs:
carbs.pop(0)
else:
fibers.pop(0)
first_dish = 'Y'
print('Y', end='')
else:
print('-', end='')
elif first_dish == 'X':
if len(carbs) >= 1 and len(fibers) >= 1 and (len(fibers)+len(carbs) >= 4):
carbs.pop(0)
fibers.pop(0)
#pop the necessary ingredients
#decide on third and fourth ingredients
for i in range(2):
try:
if carbs[0] < fibers[0]:
carbs.pop(0)
else:
fibers.pop(0)
except:
if carbs:
carbs.pop(0)
else:
fibers.pop(0)
first_dish = 'Y'
print('Y', end='')
else:
print("-", end='')
elif first_dish == 'Y':
if len(fats) >= 2 and (len(fats)+ len(fibers) >= 4):
fats.pop(0)
fats.pop(0)
for i in range(2):
try:
if fats[0] < fibers[0]:
fats.pop(0)
else:
fibers.pop(0)
except:
if fats:
fats.pop(0)
else:
fibers.pop(0)
first_dish = 'X'
print('X', end='')
else:
print("-", end='')
else:
print('-', end='')