Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package acm;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class ACM {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String a = br.readLine();
- String b = br.readLine();
- boolean res = call(a,b);
- if (res == true){
- System.out.println("YES");
- }else{
- System.out.println("NO");
- }
- }
- private static boolean call(String x, String y) {
- int Len1 = x.length()/2;
- int Len2 = y.length()/2;
- if (x.equals(y)){
- return true;
- }
- if(x.length() == 1){
- return false;
- }if(x.length() % 2 != 0){
- return false;
- }
- String s1 = x.substring(0, Len1);
- String s2 = x.substring(Len1);
- String t1 = y.substring(0, Len2);
- String t2 = y.substring(Len2);
- return (call(s1, t1) && call(s2, t2)) || (call(s1, t2) && call(s2, t1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment