Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
- public class Solution {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String farm = sc.nextLine(), state = "";
- boolean isInCage = false, isFoxOut = false, foxInCage = false;
- for (int i = 0, j = 0; i < farm.length(); i++) {
- switch (farm.charAt(i)) {
- case '[':
- isInCage = true;
- break;
- case ']':
- if (!foxInCage) state += "0";
- else foxInCage = false;
- isInCage = false;
- break;
- case 'R':
- if (!isInCage) isFoxOut = true;
- else {
- foxInCage = true;
- state += "1";
- }
- break;
- default: break;
- }
- }
- for (int i = 0, j = 0; i < farm.length(); i++) {
- char c = farm.charAt(i);
- switch(c) {
- case '[':
- isInCage = true;
- break;
- case ']':
- j++;
- isInCage = false;
- break;
- case 'A':
- if (!isInCage) { if (isFoxOut) c = '.'; }
- else if (state.charAt(j) == '1') c = '.';
- break;
- default: break;
- }
- System.out.print(c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement