Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split("#");
- int waterTotal = Integer.parseInt(scanner.nextLine());
- double totalEffort = 0;
- int totalFire = 0;
- // int cellsPutOut=0;
- List<Integer> cellsPutOut = new ArrayList<>();
- for (int i = 0; i < input.length; i++) {
- String levelOfFire = input[i];
- String[] tokens = levelOfFire.split(" = ");
- String typeOfFire = tokens[0];//high, medium, low
- int valueOfCell = Integer.valueOf(tokens[1]);//needed water
- // while (waterTotal>0){
- if (waterTotal > 0) {
- if (typeOfFire.equals("High")) {
- if (valueOfCell >= 81 && valueOfCell <= 125 && waterTotal >= valueOfCell) {
- waterTotal -= valueOfCell;
- double effort = 0.25 * valueOfCell;
- totalEffort += effort;
- totalFire += valueOfCell;
- cellsPutOut.add(valueOfCell);
- }
- } else if (typeOfFire.equals("Low")) {
- if (valueOfCell >= 1 && valueOfCell <= 50 && waterTotal >= valueOfCell) {
- waterTotal -= valueOfCell;
- double effort = 0.25 * valueOfCell;
- totalEffort += effort;
- totalFire += valueOfCell;
- cellsPutOut.add(valueOfCell);
- }
- } else if (typeOfFire.equals("Medium")) {
- if (valueOfCell >= 51 && valueOfCell <= 80 && waterTotal >= valueOfCell) {
- waterTotal -= valueOfCell;
- double effort = 0.25 * valueOfCell;
- totalEffort += effort;
- totalFire += valueOfCell;
- cellsPutOut.add(valueOfCell);
- }
- }
- }
- }
- System.out.println("Cells:");
- for (Integer integer : cellsPutOut) {
- System.out.println(" - " + integer);
- }
- System.out.printf("Effort: %.2f%n", totalEffort);
- System.out.printf("Total Fire: %d%n", totalFire);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement