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

char a[100005], b[100005];
int same(int, int, int, int);

int main()
{
    //while(1){
    int w, e;
    scanf("%s", &a);
    scanf("%s", &b);
    w = strlen(a);
    e = strlen(b);
    if(w != e){
        printf("NO\n");}
    else if(same(0, w, 0, w)==1){
        printf("YES\n");}
    else{printf("NO\n");}

    return 0;
}

int same(int al, int ar, int bl, int br)
{
    int i1,i2,j=0;
    for(i1=al,i2=bl;i1<ar,i2<br;i1++,i2++){
        if(a[i1]==b[i2]){
            j++;
            if(j==ar-al){
                return 1;
            }
        }
    }
    if((al-ar)%2!=0){
        return 0;
    }
    else{
        int amid, bmid;
        amid = (al+ar)/2;
        bmid = (bl+br)/2;
        if(same(al, amid, bl, bmid) & same(amid, ar, bmid, br)){
            return 1;
        }
        if(same(al, amid, bmid, br) & same(amid, ar, bl, bmid)){
            return 1;
        }
    }

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