文章

60

粉丝

361

获赞

41

访问

498.7k

头像
记录
P1551 东北大学机试题
发布于2021年1月19日 16:40
阅读数 7.5k

#include <iostream>
#include <string>
#include <string.h>
using namespace std;

bool levelsym(string s)
{
	int len=s.size();
	int i=0,j=len-1;
	while(i<=j)
	{
		if(s[i]!=s[j])
			return false;
		i++;
		j--;
	}
	return true;
}

int main()
{
	string levelorder;
	while(cin>>levelorder)
	{
		int index=0,len=1,flag=0;
		while((index+len)<=levelorder.size())
		{
			string s=levelorder.substr (index,len);
			//cout<<s<<endl;
			for(int i=0;i<s.size();i++)
				if(s[i]!='#')
					s[i]='a';
			if(levelsym(s)==false)
			{
				flag=1;	break;
			}
			index+=len;
			len=len*2;
		}
		if(flag==0)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发