题目:点击打开链接
1003有点小推理在里面。
//============================================================================
// Name : pat.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
char * input=new char[110];
int pIndex,tIndex,middleA,lastIndex;
bool InitAndExclude()
{
pIndex=0;
while(input[pIndex]=='A')
{
pIndex++;
}
if(input[pIndex]!='P')
{
return false;
}
middleA=1;
while(input[pIndex+middleA]=='A')
{
middleA++;
}
if(input[pIndex+middleA]!='T')
{
return false;
}
else
{
tIndex=pIndex+middleA;
middleA--;
if(middleA==0)
{
return false;
}
}
lastIndex=tIndex+1;
while(input[lastIndex]=='A')
{
lastIndex++;
}
if(input[lastIndex]!='\0')
{
return false;
}
lastIndex--;
return true;
}
bool verify()
{
while(middleA!=1)
{
int moveLastTo=lastIndex-pIndex;
for(int i=lastIndex;i>moveLastTo;i--)
{
if(input[i]!='A')
{
return false;
}
}
lastIndex=moveLastTo;
middleA--;
}
if(pIndex!=lastIndex-tIndex)
{
return false;
}
return true;
}
int main() {
int n;
cin>>n;
cin.get();
while(n--)
{
cin.getline(input,110);
if(InitAndExclude()&&verify())
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
}