Guest User

bomb

a guest
Nov 19th, 2019
227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Fundamentals.O_Ex_TextProcesing;
  2.  
  3. import java.io.Console;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Ex_7_BombExpolosition {
  9.  
  10. public static void main(String[] args) {
  11.  
  12. Scanner scanner = new Scanner(System.in);
  13. String name = scanner.nextLine();
  14. List<Character> field = new ArrayList<>();
  15.  
  16. for (int i = 0; i < name.length(); i++) {
  17. field.add(name.charAt(i));
  18. }
  19.  
  20.  
  21. int bomb = 0;
  22. for (int i = 0; i < field.size() - 1; i++) {
  23. char feldI = field.get(i);
  24. char feldIPlus = field.get(i + 1);
  25.  
  26. if (bomb > 0 && feldI != '>') {
  27. field.remove(i);
  28. bomb--;
  29. i--;
  30. }
  31.  
  32. else if (feldI == '>' && feldIPlus != '>' ) {
  33.  
  34. if (Character.isDigit(feldIPlus)) {
  35. String test = "" + feldIPlus;
  36. int temp = Integer.parseInt(test);
  37. bomb += temp;
  38. }
  39. }
  40. }
  41. for (int i = 0; i < field.size() ; i++) {
  42. System.out.print(field.get(i));
  43. }
  44.  
  45. }
  46. }
RAW Paste Data