Advertisement
Yesver08

Rubah dan Ayam

Feb 1st, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6.  
  7. public class Solution {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner sc = new Scanner(System.in);
  11.         String farm = sc.nextLine(), state = "";
  12.         boolean isInCage = false, isFoxOut = false, foxInCage = false;
  13.         for (int i = 0, j = 0; i < farm.length(); i++) {
  14.             switch (farm.charAt(i)) {
  15.                 case '[':
  16.                     isInCage = true;
  17.                     break;
  18.                 case ']':
  19.                     if (!foxInCage) state += "0";
  20.                     else foxInCage = false;
  21.                     isInCage = false;
  22.                     break;
  23.                 case 'R':
  24.                     if (!isInCage) isFoxOut = true;
  25.                     else {
  26.                         foxInCage = true;
  27.                         state += "1";
  28.                     }
  29.                     break;
  30.                 default: break;
  31.             }
  32.         }
  33.         for (int i = 0, j = 0; i < farm.length(); i++) {
  34.             char c = farm.charAt(i);
  35.             switch(c) {
  36.                 case '[':
  37.                     isInCage = true;
  38.                     break;
  39.                 case ']':
  40.                     j++;
  41.                     isInCage = false;
  42.                     break;
  43.                 case 'A':
  44.                     if (!isInCage) { if (isFoxOut) c = '.'; }
  45.                     else if (state.charAt(j) == '1') c = '.';
  46.                     break;
  47.                 default: break;
  48.             }
  49.             System.out.print(c);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement