Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package text_processing;
- import java.util.Scanner;
- public class StringExplosion_07 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine(); //"abv>1>1>2>2asdasd"
- StringBuilder textBuilder = new StringBuilder(input);
- int totalStrength = 0; //сила
- for (int position = 0; position <= textBuilder.length() - 1; position++) {
- char currentSymbol = textBuilder.charAt(position);
- if (currentSymbol == '>') {
- //експлозия
- //char ('1') -> "1" -> int 1
- int explosionStrength = Integer.parseInt(textBuilder.charAt(position + 1) + ""); //сила на експлозия
- totalStrength += explosionStrength;
- } else if (currentSymbol != '>' && totalStrength > 0) {
- //премахвам
- textBuilder.deleteCharAt(position);
- totalStrength--;
- position--;
- }
- }
- System.out.println(textBuilder);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement