题意:
给两个字符串,判断是否"相等"。
这里”相等“的定义是:1、字符串对应字符相同;
2、将第一个字符串对半分成c1和d1,第二个字符串对半分成c2和d2。
如果c1==c2 && d1==d2 或者c1==d2 && c2==d1则两个字符串相等。
当字符串长度为奇数时,只有两个字符串对应字符相同才相等。
分析:
结合题意和样例,可以看出这里的相等是递归定义。显然要用到递归。
但是用string.lengtn()和str.substr(s,e)这些库函数以及cin读入的写法在89组test上tle挂了。。
后来试着用char []来存字符串,用strncpy来截取子字符串。但是要开很多数组,而且字符串长度为200000,
不能开在函数内,不然可能爆内存。。。
其实根本不需要求子串,按照递归定义递归到最底层比较返回即可一步步回溯得到结果啊!
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
#include#include #include #include #include #include #include #include #include
下面是第一次用string敲的代码- -
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
#include#include #include #include #include #include #include #include #include