Untitled
raw download clone
TEXT
views 21
,
size 1270 b
#include <stdio.h>
#include <string.h>

int ispall(char a[100005], char b[100005], unsigned long al, unsigned long ar, unsigned long bl, unsigned long br);
int main(void) {
    
    char a[100005];
    char b[100005];
    unsigned long lena, lenb;
    
    scanf("%s", a);
    scanf("%s", b);
    lena = strlen(a);
    lenb = strlen(b);
    
    if(ispall(a, b, 0, lena - 1, 0, lenb - 1)) printf("YES\n");
    else printf("NO\n");
    
    return 0;
}

int ispall(char a[100005], char b[100005], unsigned long al, unsigned long ar, unsigned long bl, unsigned long br) {
    
    unsigned long amid, bmid;
    unsigned long i, j;
    int c = 0;
    
    i = al;
    j = bl;
    while (i <= ar && j <= br) {
        if (a[i] == b[j]) {
            c = 1;
        }
        i++;
        j++;
        if (c == 1) return 1;
    }
    if (strlen(a) % 2 == 1) {
        return 0;
    }
    else {
        amid = (al + ar) / 2;
        bmid = (bl + br) / 2;
        if ((ispall(a, b, al, amid, bl, amid)) && (ispall(a, b, amid + 1, ar, bmid + 1, br)))
            return 1;
        else if ((ispall(a, b, al, amid, bmid + 1, br)) && (ispall(a, b, amid + 1, ar, bl, bmid)))
            return 1;
        else return 0;
    }

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