Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DemoFororororLogistics {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- double priceBus = 200;
- double priceTruck = 175;
- double priceTrain = 120;
- double withBus = 0;
- int countB = 0;
- double withTruck = 0;
- double countTck = 0;
- double withTrain = 0;
- double countTrain = 0;
- double cargoNumber = 0;
- // • До 3 тона – микробус (200 лева на тон)
- //• От 4 до 11 тона – камион (175 лева на тон)
- // 12 и повече тона – влак (120 лева на тон)
- for (int i = 0; i < n; i++) {
- double cargo = Integer.parseInt(scanner.nextLine());
- cargoNumber += cargo;
- if (cargo <= 3) {
- withBus += priceBus * cargo;
- countB += cargo;
- } else if (cargo <= 11) {
- withTruck += priceTruck * cargo;
- countTck += cargo;
- } else {
- withTrain += priceTrain * cargo;
- countTrain += cargo;
- }
- }
- double cost = ((withBus + withTruck + withTrain) / cargoNumber);
- double bus = (countB / cargoNumber) * 100;
- double truck = (countTck / cargoNumber) * 100;
- double train = (countTrain / cargoNumber) * 100;
- System.out.printf("%.2f%n%.2f%%%n%.2f%%%n%.2f%%", cost, bus, truck, train);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement