Didart

String Explosion

Nov 12th, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StringExplosion {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String input = scanner.nextLine();
  8.  
  9.         StringBuilder text = new StringBuilder(input);
  10.        
  11.         int strength = 0;
  12.         for (int index = 0; index < text.length(); index++) {
  13.            
  14.             char currentSymbol = text.charAt(index);
  15.            
  16.             if (currentSymbol == '>') {
  17.                 strength += Integer.parseInt("" + text.charAt(index + 1));
  18.             } else if (currentSymbol != '>' && strength > 0){
  19.                 text.deleteCharAt(index);
  20.                 strength--;
  21.                 index--;
  22.             }
  23.         }
  24.         System.out.println(text);
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment