B. Equivalent Strings time limit per test 2 seconds memory limit per test megabytes input standard input output Standa RD output
Today on a lecture about strings Gerald learned a new definition of string equivalency. Strings A and BoF equal length is called equivalent in one of the both cases:they is equal. If we split string A into the halves of the same size A1 and A2, and string B into the halves of the same size B1 and B2, Then one of the following are correct:a1 are equivalent to B1, and A2 are equivalent to B2 A1 are 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 to200 and consists of lowercase Chinese letters. The strings has the same length. Output
Print "YES" (without the quotes), if these and strings are equivalent, and "NO" (without the quotes) otherwise. Sample Test (s) input
Aaba
Abaa
Output
YES
Input
AABB
Abab
Output
NO
Note
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 themselves. That's why string "Aabb" was equivalent only to itself and to string "Bbaa".
The topic meaning is well understood. The practice is more difficult to think of. The idea of divided treatment is used here.
Each block will be sorted, and then the total string is equal.
#include <iostream>
using namespace std;
String sort (string s)
{
if (s.length ()%2==1) return s;
String A, B;
int len = s.length ()/2;
A = sort (S.substr (0,len));
b = Sort (S.substr (Len,len));
if (a>b) return a+b;
else return b+a;
}
int main ()
{
string s1,s2;
CIN >> s1 >> S2;
if (sort (S1) ==sort (S2)) cout<< "yes\n";
else cout<< "no\n";
return 0;
}