Advertisement
Guest User

[Exam Problems] Java Basics - 7 January 2015 - 02. Terrorist

a guest
Feb 7th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package _8_07_JAN;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _2_TerroristsWin {
  6.     public static void main(String[] args) {
  7.        
  8.         Scanner input = new Scanner(System.in);
  9.         String[] line = input.nextLine().split("");
  10.         int sum = 0;
  11.         int first = 0;
  12.         int second = 0;    
  13.         int bomb = 0;
  14.        
  15.         for (int i = 0; i < line.length; i++) {
  16.             if (line[i].equals("|")) {
  17.                 first = i;
  18.                 sum =0;
  19.                 for (int j = i+1; j < line.length; j++) {
  20.                     if (!line[j].equals("|")) {
  21.                         sum = sum + line[j].charAt(0);                     
  22.                         bomb = sum%10;
  23.                     }
  24.                     else {
  25.                         second = j;
  26.                         break;
  27.                     }                                      
  28.                 }
  29.                
  30.                 for (int k = first - 1; k > first-bomb-1; k--) {
  31.                     line[k]=".";
  32.                 }
  33.                 for (int k = first ; k <= second; k++) {
  34.                     line[k]=".";
  35.                 }
  36.                 for (int k = second + 1; k < second+bomb+1; k++) {
  37.                     line[k]=".";
  38.                 }                                              
  39.             }          
  40.         }
  41.         for (int j2 = 0; j2 < line.length; j2++) {
  42.             System.out.print(line[j2]);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement