Advertisement
damesova

String Explosion

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