Untitled
raw download clone
TEXT
views 20
,
size 792 b
#include <stdio.h>
#include <string.h>

char x[100005], y[100005];

int same(int xl, int xr, int yl, int yr);
int main(void)
{
    scanf("%s", x);
    scanf("%s", y);
    int len = strlen(x);

    if (same(0, len - 1, 0, len - 1))
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

int same(int xl, int xr, int yl, int yr)
{
    int m1, m2;

    if (strncmp(x+xl, y+yl, (xr-xl+1)) == 0)
        return 1;
    else if ((xr - xl + 1) % 2 != 0)
        return 0;
    else {
        m1 = (xl + xr) / 2;
        m2 = (yl + yr) / 2;

        if (same(xl, m1, yl, m2) && same(m1, xr, m2, yr) )
            return 1;
        else if (same(xl, m1, m2, yr) && same(m1, xr, yl, m2))
            return 1;
        else    return 0;
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.