Advertisement
IrinaIgnatova

Seize the Fire

Jun 27th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.         String[] input = scanner.nextLine().split("#");
  15.         int waterTotal = Integer.parseInt(scanner.nextLine());
  16.         double totalEffort = 0;
  17.         int totalFire = 0;
  18.         // int cellsPutOut=0;
  19.         List<Integer> cellsPutOut = new ArrayList<>();
  20.  
  21.         for (int i = 0; i < input.length; i++) {
  22.             String levelOfFire = input[i];
  23.             String[] tokens = levelOfFire.split(" = ");
  24.             String typeOfFire = tokens[0];//high, medium, low
  25.             int valueOfCell = Integer.valueOf(tokens[1]);//needed water
  26.             // while (waterTotal>0){
  27.  
  28.             if (waterTotal > 0) {
  29.                 if (typeOfFire.equals("High")) {
  30.                     if (valueOfCell >= 81 && valueOfCell <= 125 && waterTotal >= valueOfCell) {
  31.                         waterTotal -= valueOfCell;
  32.                         double effort = 0.25 * valueOfCell;
  33.                         totalEffort += effort;
  34.                         totalFire += valueOfCell;
  35.                         cellsPutOut.add(valueOfCell);
  36.  
  37.  
  38.                     }
  39.                 } else if (typeOfFire.equals("Low")) {
  40.                     if (valueOfCell >= 1 && valueOfCell <= 50 && waterTotal >= valueOfCell) {
  41.                         waterTotal -= valueOfCell;
  42.                         double effort = 0.25 * valueOfCell;
  43.                         totalEffort += effort;
  44.                         totalFire += valueOfCell;
  45.                         cellsPutOut.add(valueOfCell);
  46.                     }
  47.                 } else if (typeOfFire.equals("Medium")) {
  48.                     if (valueOfCell >= 51 && valueOfCell <= 80 && waterTotal >= valueOfCell) {
  49.                         waterTotal -= valueOfCell;
  50.                         double effort = 0.25 * valueOfCell;
  51.                         totalEffort += effort;
  52.                         totalFire += valueOfCell;
  53.                         cellsPutOut.add(valueOfCell);
  54.                     }
  55.                 }
  56.             }
  57.  
  58.  
  59.         }
  60.         System.out.println("Cells:");
  61.         for (Integer integer : cellsPutOut) {
  62.             System.out.println(" - " + integer);
  63.         }
  64.  
  65.  
  66.         System.out.printf("Effort: %.2f%n", totalEffort);
  67.         System.out.printf("Total Fire: %d%n", totalFire);
  68.  
  69.  
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement