Slatter 2020-07-28 11:05 采纳率: 0%
浏览 133

PAT 我要通过! 第一个测试点始终过不了

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;
}
  • 写回答

1条回答 默认 最新

  • LTQ777 2020-07-28 14:15
    关注

    没有问题描述,没有测试数据,意义不明

    评论

报告相同问题?

悬赏问题

  • ¥15 关于SSH项目中JSP表单获取的问题
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥15 用MATLAB汇总拟合图
  • ¥15 智能除草机器人方案设计