Advertisement
Macphisto1911

String Explosion

Jul 18th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         // write your code here
  9.         Scanner scanner = new Scanner(System.in);
  10.       String text = scanner.nextLine();
  11.       StringBuilder builder = new StringBuilder();
  12.  
  13.         for (int i = 0; i < text.length() ; i++) {
  14.             char symbol = text.charAt(i);
  15.             builder.append(symbol);
  16.  
  17.             if (symbol == '>'){
  18.                 i++;
  19.  
  20.                 int power = text.charAt(i) - '0';
  21.                 int j = i ;
  22.                 for (j = i; j < i + power && j < text.length(); j++) {
  23.                     if (text.charAt(j)== '>'){
  24.                         builder.append('>');
  25.                         power += (text.charAt(j +1) - '0' + 1);
  26.                         j++;
  27.                     }
  28.                 }
  29.                 i = j - 1;
  30.  
  31.             }
  32.  
  33.         }
  34.         System.out.println(builder.toString());
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement