Untitled
raw download clone
C
views 19
,
size 1201 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];
    
    scanf("%s", a);
    scanf("%s", b);
    
    if(ispall(a, b, 0, strlen(a) - 1, 0, strlen(b) - 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 == 0 && strlen(b) % 2 == 0){
        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;
    }
    return 0;

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