Професионална програма
Loading...
georgievmartin17 avatar georgievmartin17 6 Точки

80 /100 в Judge, изчисленията излизат верни. Задача "Toy Shop", Conditional statements Lab

import java.util.Scanner;

public class NewToy {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);


        double excPrice = Double.parseDouble(scanner.nextLine());
        int puzzles = Integer.parseInt(scanner.nextLine());
        int dolls = Integer.parseInt(scanner.nextLine());
        int teddybears = Integer.parseInt(scanner.nextLine());
        int minions = Integer.parseInt(scanner.nextLine());
        int lorries = Integer.parseInt(scanner.nextLine());


        double allToysPrice = (puzzles * 2.6) + (dolls * 3.0) + (teddybears * 4.10) + (minions * 8.2) + (lorries * 2.0);

        int allToys = puzzles + dolls + teddybears + minions + lorries;

        double rent = allToysPrice * 0.1;

        double finalSum = allToysPrice - rent;

        if (allToys > 50) {
            finalSum = finalSum * 0.75;
        }



        if (finalSum >= excPrice) {
            double diff = finalSum - excPrice;

            System.out.printf("Yes! %.2f lv left.", diff);

        }else if ( excPrice > finalSum){

            double diff = excPrice - finalSum;
            System.out.printf("Not enough money! %.2f lv needed.", diff);
        }


    }
}
0
Programming Basics with Java
AlexKadiyski avatar AlexKadiyski 16 Точки

Решението е на C#, логиката е същата:
 

using System;

namespace _07._Toy_Shop
{
    class Program
    {
        static void Main(string[] args)
        {
            double travelPrice = double.Parse(Console.ReadLine());
            int soldPuzzels = int.Parse(Console.ReadLine());
            int soldDolls = int.Parse(Console.ReadLine());
            int soldTeddybears = int.Parse(Console.ReadLine());
            int soldMinions = int.Parse(Console.ReadLine());
            int soldTrucks = int.Parse(Console.ReadLine());

            double puzzelsMoney = soldPuzzels * 2.60;
            double dollsMoney = soldDolls * 3;
            double teddybearsMoney = soldTeddybears * 4.1;
            double minionsMoney = soldMinions * 8.2;
            double trucksMoney = soldTrucks * 2;

            double total = puzzelsMoney + dollsMoney + minionsMoney + teddybearsMoney + trucksMoney;

            int soldToys = soldPuzzels + soldDolls + soldTeddybears + soldTrucks + soldMinions;

            if (soldToys >= 50)
            {
                total = total * 0.75;
            }
            total = total * 0.9;

            if (total >= travelPrice)
            {
                double remaining = total - travelPrice;
                Console.WriteLine($"Yes! {remaining:f2} lv left.");
            }
            else
            {
                double neededMoney = travelPrice - total;
                Console.WriteLine($"Not enough money! {neededMoney:f2} lv needed.");
            }
        }
    }
}
 

0