Tarango

Untitled

Jul 22nd, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package acm;
  7.  
  8.  
  9. import java.io.BufferedReader;
  10. import java.io.IOException;
  11. import java.io.InputStreamReader;
  12.  
  13. public class ACM {
  14.    
  15.     public static void main(String[] args) throws IOException {
  16.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  17.         String a = br.readLine();
  18.         String b = br.readLine();
  19.         boolean res = call(a,b);
  20.         if (res == true){
  21.             System.out.println("YES");
  22.         }else{
  23.             System.out.println("NO");
  24.         }
  25.     }
  26.    
  27.     private static boolean call(String x, String y) {
  28.         int Len1 = x.length()/2;
  29.         int Len2 = y.length()/2;
  30.         if (x.equals(y)){
  31.             return true;
  32.         }
  33.         if(x.length() == 1){
  34.             return false;
  35.         }if(x.length() % 2 != 0){
  36.             return false;
  37.         }
  38.         String s1 = x.substring(0, Len1);
  39.         String s2 = x.substring(Len1);
  40.         String t1 = y.substring(0, Len2);
  41.         String t2 = y.substring(Len2);
  42.  
  43.         return (call(s1, t1) && call(s2, t2)) || (call(s1, t2) && call(s2, t1));
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment