mr_anastasov

codexio_ColoredBalls

Nov 13th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String input;
  8.         String color;
  9.         int count;
  10.         int absoluteCount = 0;
  11.         int result = 0;
  12.         String colorCheck = "transparent";
  13.  
  14.         while (scanner.hasNextLine()) {
  15.             input = scanner.nextLine();
  16.  
  17.             if (input.equalsIgnoreCase("end")) {
  18.                 break;
  19.             }
  20.  
  21.             String[] inputLine = input.split(":");
  22.             color = inputLine[0].trim();
  23.             count = Integer.parseInt(inputLine[1].trim());
  24.             absoluteCount += count;
  25.             if (colorCheck.equalsIgnoreCase(color)) {
  26.                 result = 0;
  27.             } else {
  28.                 result = absoluteCount - 1;
  29.             }
  30.             colorCheck = color;
  31.         }
  32.         System.out.println(result);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment