需要注意:左侧A的数量*中间A的数量=右侧A的数量
分析在这里:分析
if __name__ == '__main__':
n = int(input())
res = []
for i in range(n):
s = input()
isTrue = True
hasA = False
l = 0
m = 0
r = 0
if s.count("P") == 1 and s.count("T") == 1:
for j in range(s.find("P")):
if s[j] != " " and s[j] != "A":
isTrue = False
break
if s[j] == "A":
l += 1
for j in range(s.find("P") + 1, s.find("T")):
if s[j] != " " and s[j] != "A":
isTrue = False
break
if s[j] == "A":
m += 1
hasA = True
for j in range(s.find("T") + 1, len(s)):
if s[j] != " " and s[j] != "A":
isTrue = False
break
if s[j] == "A":
r += 1
if l * m != r:
isTrue = False
else:
isTrue = False
if isTrue and hasA:
res.append("YES")
else:
res.append("NO")
for i in res:
print(i)