Advertisement
Guest User

Untitled

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