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

char a[100002], b[100002];
int lena, lenb;
int compare(int al, int ar, int bl, int br);

int main(void){
	scanf("%s", a);
	scanf("%s", b);
	lena = strlen(a);
	lenb = strlen(b);
	if(compare(0, lena-1, 0, lenb-1)) printf("YES\n");
	else printf("No\n");

	return 0;
}

int amid, bmid, i, j;
char newa[100002], newb[100002];

int compare(int al, int ar, int bl, int br){
	int flag = 1;
	for(i=al, j=bl; i <=ar || j<=br; i++, j++){
		if(a[i] != b[j]){
			flag = 0;
			break;
		}
	}
	if(flag == 1) return 1;
	else if((ar-al) % 2 == 0) return 0;
	else {
		if(compare(al, (al+ar)/2, bl, (bl+br)/2) && compare((al+ar)/2+1, ar, (bl+br)/2+1, br)) return 1;
		else if(compare(al, (al+ar)/2, (bl+br)/2+1, br) && compare((al+ar)/2+1, ar, bl, (bl+br)/2)) return 1;
		else return 0;
	}
	return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.