文章
3
粉丝
370
获赞
6
访问
27.2k
#include <bits/stdc++.h>
using namespace std;
bool symmetry(string s,int l,int r)//l是左边待判断的结点号,r是右边
{
if(l>=s.length())return true;
if(r>=s.length()&&s[l]=='#')
return true;
if(r>=s.length()&&s[l]!='#')
return false;
if((s[l]=='#'&&s[r]!='#')||(s[l]!='#'&&s[r]=='#'))
return false;
if(symmetry(s,2*l+1,2*r+2)&&symmetry(s,2*l+2,2*r+1))//左往右,右往左,判断是不是对称;然后左往左,右往右判断;
return true;
else return false;
}
int main()
{
string s;
cin>>s;
if(symmetry(s,1,2))
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发