Untitled
raw download clone
C
views 90
,
size 963 b
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char a[100005];
char b[100005];
int f(int al, int ar, int bl, int br){
    int i, j, k;

    i = al;
    j = bl;
    k = 0;
    while(i<=ar && j<=br){
        if(a[i] == b[j]) k++;
        if(k == (ar-al+1)) return 1; //當k==字串長度,代表兩字串每個字都相等
        i++; j++;
    }
    if(((ar-al+1)%2 == 1)&&((br-bl+1)%2 == 1)) return 0;
        else{
            int amid = (al+ar)/2;
            int bmid = (bl+br)/2;
            if (f(al, amid, bl, bmid) && f(amid, ar, bmid, br))
                return 1;
            else if (f( al, amid, bmid, br) && f(amid, ar, bl, bmid))
                return 1;
            else
                return 0;
        }
}
int main ( ){
    int i, len;
    scanf("%s%s", a, b);
    len = strlen(a);
    if(f(0, len-1, 0, len-1))
        printf("YES\n");
    else
        printf("NO\n");

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