Untitled
raw download clone
C
views 26
,
size 1253 b
#include<stdio.h>
#include<string.h>
char a[100005], b[100005];
char tempA[100005], tempB[100005];

int main()
{

    int a_len, b_len;

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

    a_len = strlen(a);
    b_len = strlen(b);

    //func(0, len_a-1, 0, len_b-1);

    if (func(0, a_len-1, 0, b_len-1) == 1)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

int func(int al, int ar, int bl, int br)
{
    int p = 0, k = 0;
    for (int i = 0; i <= ar-al+1; i++)
    {
        tempA[i] = 0;
    }
    for (int i = 0; i <= ar-al+1; i++)
    {
        tempB[i] = 0;
    }

    for (int i = al; i <= ar; i++)
    {
        tempA[p] = a[i];
        p++;
    }
    for (int i = bl; i <= br; i++)
    {
        tempB[k] = b[i];
        k++;
    }

    if (strcmp(tempA, tempB) == 0)
        return 1;
    else if ( (ar-al+1) % 2 != 0)
        return 0;
    else
    {
        int a_mid = (al + ar) / 2;
        int b_mid = (bl + br) / 2;

        if (func(al, a_mid, bl, b_mid) && func(a_mid, ar, b_mid, br))
            return 1;
        else if (func(a_mid, al, br, b_mid) && func(ar, a_mid, b_mid, bl))
            return 1;
        else
            return 0;
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.