Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bg.softuni.javafundamentals;
- import java.util.Scanner;
- public class E07StringExplosion2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- StringBuilder sb = new StringBuilder(scanner.nextLine());
- int strengthOfExplosion = 0;
- for (int i = 0; i < sb.length(); i++) {
- if (sb.charAt(i) == '>') {
- int a = Character.getNumericValue(sb.charAt(i + 1));
- strengthOfExplosion += a;
- } else {
- if (strengthOfExplosion > 0) {
- sb.deleteCharAt(i);
- strengthOfExplosion--;
- i--; // return to the previous symbol
- }
- }
- }
- System.out.println(sb);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment