Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.telerikacademy.web.springdemo;
- import java.util.Scanner;
- public class Main {
- /**
- * All cases
- * 1. Truck capacity is equal to all big bottles
- * 2. Truck capacity is more than all bottles
- * 3. Truck capacity is less than all big bottles
- * 3.1 Truck capacity is not equally divided to the big bottles
- * 3.1.1 The remainder is equal to all small bottles
- * 3.1.2 The remainder is more than all small bottles
- * 3.1.3 The remainder is less than all small bottles
- * 4. Truck capacity is more than all big bottles
- * 4.1 The small bottles are less than the left space
- * 4.2 The small bottles are equal or more than to the left space
- */
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int allSmallBottles = Integer.parseInt(scanner.nextLine());
- int allBigBottles = Integer.parseInt(scanner.nextLine()) * 5;
- int truckCapacity = Integer.parseInt(scanner.nextLine());
- int allBottles = allSmallBottles + allBigBottles;
- int freeCapacity = truckCapacity - allBigBottles;
- int truckIsFull = 0;
- int truckNotFull = -1;
- if (truckCapacity == allBigBottles){
- System.out.println(truckIsFull);
- } else if (truckCapacity > allBottles){
- System.out.println(truckNotFull);
- } else if (allBigBottles > truckCapacity){
- int remainder = truckCapacity % 5;
- if (remainder == 0){
- System.out.println(truckIsFull);
- } else {
- System.out.println(remainder);
- if (remainder > allSmallBottles){
- System.out.println(-1);
- } else{
- System.out.println(remainder);
- }
- }
- } else {
- if (freeCapacity > allSmallBottles) {
- System.out.println(truckNotFull);
- } else {
- System.out.println(freeCapacity);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment