chillurbrain

Доп. из 10.2. Эквивалентные строки.

May 26th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EquivalentString {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         String s1 = sc.nextLine();
  7.         String s2 = sc.nextLine();
  8.         if(equi(s1, s2))
  9.             System.out.println("YES");
  10.         else System.out.println("NO");
  11.     }
  12.  
  13.     public static boolean equi(String s1,String s2){
  14.         int len=s1.length();
  15.         if(len % 2 == 1) {
  16.             if(s1.equals(s2))
  17.                 return true;
  18.             else return false;
  19.         } else {
  20.             String s3=s1.substring(0,len/2);
  21.             String s4=s1.substring(len/2);
  22.             String s5=s2.substring(0,len/2);
  23.             String s6=s2.substring(len/2);
  24.             return ((equi(s3,s5)) && (equi(s4,s6))) || ((equi(s4,s5)) && (equi(s3,s6)));
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment