559B Codeforces - Equivalent Strings





Solution in c++

#include <iostream>

using namespace std;

string inp,inpp;

string div(string a)
{

    int sz=a.size();
    if (sz%2)return a;
    string hav1=div(a.substr(0,sz/2));
    string hav2=div(a.substr(sz/2,sz/2));
    return hav1<hav2 ?hav1+hav2 :hav2+hav1 ;
}

int main()
{
    getline(cin,inp);
    getline(cin,inpp);
    cout<<((div(inp) == div(inpp))?"YES\n":"NO\n");
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق