equivalent StringsE-Brute force solver, DFSTime
limit:2000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u
Description
Today on a lecture about strings Gerald learned a new definition of string equivalency. Strings a and b of equal length is called equivalent in one of the of theCASES:
- They is equal.
- If We split string a into both halves of the same Size a 1 and a 2, and String b into both halves of the same size b 1 and b 2, then one of the following is correct: /sub>
- a 1 is equivalent to b1, and a2 are equivalent to b2
- a 1 is equivalent to b2, and a2 are equivalent to b1
As a home task, the teacher gave the strings to his students and asked to determine if they is equivalent.
Gerald have already completed this home task. Now it ' s your turn!
Input
The first and lines of the input contain the strings given by the teacher. Each of them have the length from 1 to and consists of lowercase 中文版 letters. The strings has the same length.
Output
Print "YES" (without the quotes), if these, strings is equivalent, and "NO" (without the quotes) otherwise.
Sample Input
Input
CA A
Abaa
Output
YES
Input
Aabb
Abab
Output
NO
Hint
In the first sample you should split the first string into strings "aa" and "ba ", the second One-into strings" ab "and" aa". "aa" is equivalent to "AA"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can is splitted into strings "AA" and "BB", which is equivalent only to them Selves. That's why string "Aabb" was equivalent only to itself and tostring "Bbaa".
Test instructions: to two strings, to determine whether they are equal, two cases of equality, one is the string directly equal, one is cut into the same length of two copies of the two substrings equal (two cases)
Puzzle: Direct judgment of the line, if the current length is odd, if not exactly equal, directly return 0, otherwise divided into two cases of judgment
#include <stdio.h>#include<string.h>Chara[200005],b[200005];intJuge (Char*p,Char*q,intLen) { if(!STRNCMP (P,q,len))//determine if the string length is equal p,q return-1; if(len%2) return 0;//End Judgment intmid=len/2; if(Juge (P,q+mid,mid) &&juge (p+Mid,q,mid)) return-1; if(Juge (P+mid,q+mid,mid) &&juge (p,q,mid))return-1;}intMain () {scanf ("%s%s",&a,&b); if(Juge (A,b,strlen (a))) printf ("YES"); Elseprintf ("NO"); return 0;}
Equivalent Strings (string equals?) )