Untitled
raw download clone
C
views 19
,
size 1149 b
12133

#include <stdio.h>
#include <string.h>

char a[100005], b[100005];
void show(int a)
{
    if (a == 1) printf("YES\n");
    else if (a == 0)printf("NO\n");
}

int function(int al, int ar, int bl, int br)
{
    int flag = 0;
    int aMid, bMid;
    for (int i = al, j = bl;i <= ar, j <= br;i++, j++)
    {
        if (a[i] != b[j])
        {
            flag = 1;
            break;
        }
    }
    if (flag == 0)
    {
        return 1;
    }
    if ((ar - al + 1) % 2 == 1)
    {
        return 0;
    }
    else
    {
        aMid = (al + ar + 1) / 2;
        bMid = (bl + br + 1) / 2;
        if (function(al, aMid-1, bl, bMid-1) && function(aMid, ar, bMid, br))
        {
            return 1;
        }
        else if (function(al, aMid-1, bMid, br) && function(aMid, ar, bl, bMid-1))
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
}

int main(void)
{
    int aLen, bLen;
    scanf("%s", a);
    scanf("%s", b);
    aLen = strlen(a)-1;
    bLen = strlen(b)-1;
    show(function(0, aLen, 0, bLen));

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.