svetlozar_kirkov

Terrorists Win [Java Exam]

Oct 4th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package com.sve;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class Playground {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         char[] inputLineChars = scan.nextLine().toCharArray();
  11.         for (int i = 0; i < inputLineChars.length; ) {
  12.             if (inputLineChars[i] == '|') {
  13.                 int startIndex = i;
  14.                 int bombLength = 1;
  15.                 int bombSum = 0;
  16.                 i++;
  17.                 while (inputLineChars[i] != '|') {
  18.                     bombSum += (int)inputLineChars[i];
  19.                     i++;
  20.                     bombLength++;
  21.                 }
  22.                 bombLength++;
  23.                 int lastDigit = bombSum % 10;
  24.                 int startOfDots = 0;
  25.                 int endOfDots = inputLineChars.length;
  26.                 if (startIndex - lastDigit >= 0) {
  27.                     startOfDots = startIndex - lastDigit;
  28.                 }
  29.                 if ((startIndex - lastDigit) + (lastDigit + bombLength) + lastDigit < inputLineChars.length) {
  30.                     endOfDots = (startIndex - lastDigit) + (lastDigit + bombLength) + lastDigit;
  31.                 }
  32.                 for (int j = startOfDots; j < endOfDots; j++) {
  33.                     inputLineChars[j] = '.';
  34.                 }
  35.             }
  36.             i++;
  37.         }
  38.         System.out.println(Arrays.toString(inputLineChars).replace("[", "").replace(", ", "").replace("]", ""));
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment