CF 559B equivalent Strings

Source: Internet
Author: User
Tags first string sort split time limit
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;
}


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.