PAT乙级, 原题链接

运行测试结果,第5个测点过不去

1003 我要通过!请大佬帮忙!!! 感谢

代码C++

#include<iostream>
#include<string.h>
using namespace std;
void judge(char *s);
int main()
{
	int n;
	cin >> n; //输入n行测试
	getchar();

	while (n-- > 0) //读取每行并作判断和输出
	{
		char str[100]; //保存读入的字符串
		cin.getline(str, 100);
		judge(str);
	}
	return 0;
}
/* 判断函数*/
void judge(char *s)
{
	char *p = s;
	int count[3] = { 0 }; // 记录_P_T_ 之间A的个数
	int index = 0;

	while (*p != '\0')
	{
		if (*p == 'A')
			count[index] += 1;
		else if (index == 0 && *p == 'P')//保证P只出现过一次
			index++;
		else if (index == 1 && *p == 'T') //保证T前面有过P
			index++;
		else
			break;
		p++;
	}
	if (count[1] != 0 && (index == 2) && (count[2] == count[0] * count[1])) // 保证PT各有一个,且A的数量满足规律
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

请大佬帮忙!!! 感谢

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2021-10-30
  • 2021-10-07
  • 2021-08-09
  • 2022-01-20
  • 2021-05-26
  • 2021-07-14
  • 2021-09-16
相关资源
相似解决方案