Advertisement
deyanmalinov

07. String Explosion

Mar 25th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.        String text = scan.nextLine();
  9.        String res = "";
  10.         for (int i = 0; i < text.length(); i++) {
  11.             char bomb = text.charAt(i);
  12.             if (bomb =='>'){
  13.                 res+=bomb;
  14.                 i++;
  15.                 int explosion = text.charAt(i) - '0';
  16.                 explosion--;
  17.                 while (explosion > 0 && i < text.length()-1){
  18.                     i++;
  19.                     bomb = text.charAt(i);
  20.                     if (bomb == '>'){
  21.                         res+=bomb;
  22.                         i++;
  23.                         explosion += text.charAt(i) - '0';
  24.                         explosion--;
  25.                         continue;
  26.                     }
  27.                    explosion--;
  28.                 }
  29.             }else {
  30.                 res+= bomb;
  31.             }
  32.         }
  33.         System.out.println(res);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement