PAT 我要通过!
第一个测试点始终过不了
自己写的代码如下,感觉也没啥问题,但是测试点1就是过不了,有没有大佬帮忙看一下哪里有问题
#include <iostream>
#include <string>
using namespace std;
void solve(string str)
{
int count1 = 0;
int count2 = 0;
int count3 = 0;
int index = 0;
bool flag1 = true;
bool flag2 = false;
bool flag3 = false;
while (flag1 && index < str.size()) //三个while统计三个部分的A字符数目
{
if (str[index] == 'A')
{
count1++;
}
else if (str[index] == 'P')
{
flag1 = false;
flag2 = true;
}
else
{
cout << "NO" << endl;
return;
}
index++;
}
while (flag2 && index < str.size())
{
if (str[index] == 'A')
{
count2++;
}
else if (str[index] == 'T')
{
flag2 = false;
flag3 = true;
}
else
{
cout << "NO" << endl;
return;
}
index++;
}
while (flag3 && index < str.size())
{
if (str[index] == 'A')
{
count3++;
}
else
{
cout << "NO" << endl;
return;
}
index++;
}
if (count1 * count2 == count3 && count2 > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main()
{
int num;
cin >> num;
for (int i = 0; i < num; i++)
{
string str;
cin >> str;
solve(str);
}
return 0;
}