Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input;
- String color;
- int count;
- int absoluteCount = 0;
- int result = 0;
- String colorCheck = "transparent";
- while (scanner.hasNextLine()) {
- input = scanner.nextLine();
- if (input.equalsIgnoreCase("end")) {
- break;
- }
- String[] inputLine = input.split(":");
- color = inputLine[0].trim();
- count = Integer.parseInt(inputLine[1].trim());
- absoluteCount += count;
- if (colorCheck.equalsIgnoreCase(color)) {
- result = 0;
- } else {
- result = absoluteCount - 1;
- }
- colorCheck = color;
- }
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment