因为PAT上GCC的版本是4.7.5,所以不支持C++11的正则,就用Python写了
#coding=utf-8
import re
n=int(input())
index=0;
L=[]
while(index<n):
string=input()
L.append(string)
index+=1
for var in L:
matchObj=re.match(r'(?P<x>A*)P(?P<y>A+)T(?P<z>\1+)$',var)
if matchObj:
if len(matchObj.group('x'))==0 and len(matchObj.group('z'))==0 or len(matchObj.group('y'))==len(matchObj.group('z'))/len(matchObj.group('x')):
print("YES")
else:
print("NO")
else:
print("NO")