Equivalent Strings (string equals?) )

Source: Internet
Author: User

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:

  1. They is equal.
  2. 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>
      1. a 1 is equivalent to b1, and a2 are equivalent to b2
      2. 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?) )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.