Untitled
raw download clone
C
views 23
,
size 1145 b
#include<stdio.h>
#include<string.h>

int loop(int, int, int, int);
char a[100005], b[100005];
char c[100005], d[100005];

int main()
{

    int len_a, len_b, flag;

    scanf("%s", &a);
    scanf("%s", &b);

    len_a = strlen(a);
    len_b = strlen(b);

    flag = loop(0, len_a-1, 0, len_b-1);

    if (flag == 1)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

int loop(int a1, int a2, int b1, int b2)
{
    int j = 0, k = 0;

    char c[100005]={0};
    char d[100005]={0};

    for (int i = a1;i <= a2;i++)
    {
        c[j] = a[i];
        j++;
    }
    for (int i = b1;i <= b2;i++)
    {
        d[k] = b[i];
        k++;
    }

    if (strcmp(c, d) == 0)
        return 1;
    else if ( (a2-a1+1) % 2 != 0)
        return 0;
    else
    {
        int amid = (a1 + a2) / 2;
        int bmid = (b1 + b2) / 2;

        if (loop(a1, amid, b1, bmid) && loop(amid+1, a2, bmid+1, b2))
            return 1;
        else if (loop(a1, amid, bmid+1, b2) && loop(amid+1, a2, b1, bmid))
            return 1;
        else
            return 0;
    }

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