svephoto

Text Explosion

Nov 19th, 2019
790
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class TextExplosion {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String name = scanner.nextLine();
  10.  
  11. List<Character> field = new ArrayList<>();
  12.  
  13. for (int i = 0; i < name.length(); i++) {
  14. char symbol = name.charAt(i);
  15. field.add(symbol);
  16.  
  17. if (symbol == '>') {
  18. i++;
  19. int bomb = name.charAt(i) - '0';
  20.  
  21. int j = i;
  22. for (; j < i + bomb && j < name.length(); j++) {
  23. if (name.charAt(j) == '>') {
  24. field.add('>');
  25. j++;
  26. bomb += (name.charAt(j) - '0') + 1;
  27. }
  28. }
  29.  
  30. i = j - 1;
  31. }
  32. }
  33.  
  34. for (int i = 0; i < field.size() ; i++) {
  35. System.out.print(field.get(i));
  36. }
  37. }
  38. }
RAW Paste Data