1.这道题最开始的思想错了,后来上网上查了解题关键。
2.目前可能存在错误,因为在我的codeblocks上没有错误,并且结果正确。但是在PTA上有运行时错误,不知道怎么错了。
哎 有人可以帮我看下吗
#include <iostream>
#include <string>
using namespace std;
string del(string a,string b)
{
unsigned int t=a.find(b);
string c;
while(t!=string::npos)
{
c=a.erase(t,1);
t=a.find(b);
}
return c;
}
void daan(string a)
{
string b=a;
b=del(b,"P");
b=del(b,"A");
b=del(b,"T");
if(b=="")
{
int len=a.length();
int lena,lenb,lenc;
lena=a.find_first_not_of("A",0);
lenb=a.find_first_not_of("A",lena+1)-lena-1;
lenc=len-lena-lenb-2;
if((lena*lenb==lenc)&&(lenb!=0))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
else
{
cout<<"NO"<<endl;
}
}
int main()
{
int n;
cin>>n;
string a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int j=0;j<n;j++)
{
daan(a[j]);
}
return 0;
}