Advertisement
desislava_topuzakova

07. String Explosion

Jul 15th, 2022
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StringExplosion_07 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. String input = scanner.nextLine();
  7. //"abv>1>1>2>2asdasd"
  8. StringBuilder text = new StringBuilder(input);
  9.  
  10. int totalStrength = 0; //сила
  11. for (int position = 0; position < text.length() ; position++) {
  12. char currentSymbol = text.charAt(position);
  13. if (currentSymbol == '>') {
  14. //char ('1') -> string ("1") -> int (1)
  15. //атака
  16. int attackStrength = Integer.parseInt(text.charAt(position + 1) + ""); //сила на атаката
  17. totalStrength += attackStrength;
  18. } else if (currentSymbol != '>' && totalStrength > 0) {
  19. //премахване
  20. text.deleteCharAt(position);
  21. totalStrength--;
  22. position--;
  23.  
  24. }
  25. }
  26. System.out.println(text);
  27.  
  28.  
  29. }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement