The program takes as input a data-set of orders where id, t selection and t shipping are of type unsigned int, n is the number of orders, and a space character. id1, t selection1, t shipping1; ...; idn, t selectionn, t shippingn \n. The expected output is a space-separated list of the ids, sorted by t selection + t shipping and terminated by a newline \n.
Input: 1, 500, 100; 2, 700, 100; 3, 100, 100; 4, 50, 50\n
Output: 4 3 1 2\n
My output however shows this
output: 4 1 2 3
Could somebody help me fix this? thanks in advance. below you can see my code. in the code there are some annotations from my teacher btw, don't mind them.
#!/usr/bin/env python3
import sys
class Order:
def __init__(self, id: int, selection_time: int, shipping_time: int):
self.id: int = id
self.selection_time: int = selection_time
self.shipping_time: int = shipping_time
'''
Remove me if you don't need me.
Add a method to assign to me.
'''
self.next: Order = None
'''
Make your life easier and your code prettier, use `Operator Overloading`.
'''
def sort(data):
sorted_order = selection_t + shipping_t
for i in range(len(data)):
for j in range(i + 1, len(data)):
if sorted_order[i] > sorted_order[j]:
data[i], data[j] = data[j], data[i]
return data
if __name__ == '__main__':
'''
Retrieves and splits the input
'''
data = input()
data = data.split('; ')
for d in data:
id, selection_t, shipping_t = d.split(', ', 2)
order: Order = Order(int(id), int(selection_t), int(shipping_t))
sort(data)
for order.id in data:
sys.stdout.write(order.id[0])
sys.stdout.write(" ")