Advertisement
meteor4o

JF-TextProcessing-Exercise-07.StringExplosion

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