[2016-03-23][codeforces][560][D][Equivalent Strings]

  • 时间:2016-03-23 14:15:39 星期三

  • 题目编号:[2016-03-23][codeforces][560][D][Equivalent Strings]

  • 题目大意:定义两个字符串相等方式,给出两个字符串,问是否相等

  • 分析:递归判断即可

  • 遇到的问题:长度为奇数的字符串一定不相等

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int issame(string str1,string str2){
  5. if(str1 == str2){
  6. return 1;
  7. }
  8. int m = str1.length();
  9. if(m & 1) return 0;
  10. return (issame(str1.substr(0,m/2),str2.substr(m/2,m/2))&&issame(str1.substr(m/2,m/2),str2.substr(0,m/2)))||
  11. (issame(str1.substr(0,m/2),str2.substr(0,m/2))&&issame(str1.substr(m/2,m/2),str2.substr(m/2,m/2)));
  12. }
  13. int main(){
  14. string str1,str2;
  15. cin>>str1>>str2;
  16. cout<<(issame(str1,str2)?"YES":"NO")<<'\n';
  17. return 0;
  18. }


来自为知笔记(Wiz)


posted on 2016-03-23 18:36  红洋  阅读(112)  评论(0)    收藏  举报

导航