Задача02 Тръби в басейн Exam 26March2016
Дали някой би могъл да предложи решение на въпросната задача, само че да е на Java, и да взима 100 точки в джъджа. Моето решение, което давам по-долу, получава 73 точки. Проблемът е, че при някои тестове моя код принтира стойности от тип дабъл с излишни нули след запетайката. Например при вход със стойности 100, 100, 100, 2.5 (това е тест 2) очакваният изход е "For 2.5 hours the pool overflows with 400 liters",а моят изход е "For 2.5 hours the pool overflows with 400.0 liters."
import java.util.Scanner;
 
public class PoolPipes2
{
    public static void main( String[] args )
    {
        Scanner input = new Scanner(System.in);
         
        
        int v = Integer.parseInt(input.nextLine());
        int p1 = Integer.parseInt(input.nextLine());
        int p2 = Integer.parseInt(input.nextLine());
        double h = Double.parseDouble(input.nextLine());
        
        double actualLitres = (p1+p2)*h;
        
        
        if(actualLitres <= v)
        {
            double percentagePool = Math.floor((actualLitres/v)*100);
            double percentageP1 = Math.floor((p1*h/actualLitres)*100);
            double percentageP2 = Math.floor((p2*h/actualLitres)*100);
            int per100Pool =  (int) percentagePool;
            int per100P1 = (int) percentageP1;
            int per100P2 = (int) percentageP2;
            System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.%n",
                                                                                per100Pool,  per100P1,  per100P2);
        }
        else
        { 
            double overflow = actualLitres - v;
            System.out.printf("For %.1f hours the pool overflows with %.1f liters.%n", h , 
                                                                            overflow);
        }
    }
}