You are responsible for the logistics various types of cargo. Depending on the weight of each cargo, you need a different vehicle and this will cost a different price per tonne:
- Up to 3 tonnes – a minibus (200 lv per tonne).
- From over 3 and up to 11 tonnes – truck (175 lv per tonne).
- Over 11 tonnes – train (120 lv per tonne).
Your task is to calculate the average price per tonne of the cargo, and also what percentage of the cargo is transported in each vehicle .
From the console we must read a sequence of numbers, each on a separate line:
- First line: count of cargo for transportation – integer in the range of [1 … 1000].
- On the next lines we pass the tonnage of the current cargo – integer in the range of [1 … 1000].
Print on the console 4 lines, as follows:
- Line #1 – the average price per tonne of the cargo (rounded up to the second digit after the decimal point).
- Line #2 – percentage of the cargo, carried by minibus (between 0.00% and 100.00%, rounded up to the second digit after the decimal point).
- Line #3 – percentage of the cargo, carried by truck (between 0.00% and 100.00%).
- Line #4 – percentage of the cargo, carried by train (between 0.00% and 100.00%).
By minibus you transport two of the cargo 1 + 3, total of 4 tonnes.
By truck you transport one of the cargo: 5 tonnes.
By train you transport one of the cargo: 16 tonnes.
Sum of all cargo is: 1 + 5 + 16 + 3 = 25 tonnes.
Percentage of the cargo by minibus: 4/25*100 = 16.00%
Percentage of the cargo by truck: 5/25*100 = 20.00%
Percentage of the cargo by train: 16/25*100 = 64.00%
Average price per tonne of carried cargo: (4 * 200 + 5 * 175 + 16 * 120) / 25 = 143.80
First we will read the weight of each cargo and sum how much tonnes are being transported by minibus, truck and train, and we will calculate the total tonnes of the transported cargo. We will calculate prices for each type of transportation according to the transported tonnes and the total price. Finally, we will calculate and print the total average price per tonne and how much of the cargo is being transported by different types of transport in percents.
We declare the needed variables, for example:
countOfLoads – count of the cargos for transportation (we read them from the console),
sumOfTons – sum of the tonnage of all cargos,
trainTons – variables that keeps the sum of the cargo tonnage, transported by minibus, truck and train.
We sill need a
for loop from
countOfLoads-1, to iterate through all cargo types. For each cargo we read its weight (in tonnes) from the console and save it in a variable, for example
tons. We add to the tonnage the sum of all cargo (
sumOfTons) the weight of the current cargo (
tons). Once we have read the weight of the current cargo we need to determine which vehicle type will be used (minibus, truck or train). For this we will need
If the value of the variable
tonsis less than 3, increase the value of
microbusTonsby the value of
microbusTons += tons;
Otherwise, if the value
tonsis less than 11, increase
tonsis more than 11, increase
Before we print the output, we need to calculate the percentage of tonnes, transported by each vehicle and the average price per tonne. For the average price per tonne we will declare one more helper variable
totalPrice, in which we will sum the total price of all transported cargo (by minibus, truck and train). We will calculate an average price, by dividing
sumOfTons. You need to calculate by yourself the percentages of tonnes, transported by each vehicle, and print the results, keeping the format specified in the description.
Test your solution here: https://judge.softuni.org/Contests/Practice/Index/511#5.