题目大意:
给出两个字符串,判断是否相等,定义字符串是否相等的方法为,如果为奇数串,只能比较是否每个字符相同,如果为偶数串,第一个串分成两个相等长度的串为a1 b1,第二个串也分成a2 b2,a1== a2 && b1 == b2 || a1 == b2 && a2 == b2。
解题思路:
直接暴力递归,不虚。
还见识到了一个函数,strncmp(a,b,l);
判断a,b两个字符串前l位是否相等。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <map>
#include <set>
using namespace std;
int a, b, c,len;
char s1[200500],s2[200500];
int DFS(char *a,char *b,int l){
if (strncmp(a,b,l)==0) {return 1;}
if (l%2) {return 0;}
int p=l/2;
if((DFS(a,b+p,p) && DFS(a+p,b,p)) || (DFS(a,b,p) && DFS(a+p,b+p,p))) {return 1;}
}
int main()
{
gets(s1);
gets(s2);
len=strlen(s1);
int pk=DFS(s1,s2,len);
if (pk==1) printf("YES\n");
else printf("NO\n");
return 0;
}