1003. 我要通过!

答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。

得到“答案正确”的条件是:

1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;
2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;
3. 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a, b, c 均或者是空字符串,或者是仅由字母 A 组成的字符串。

现在就请你为PAT写一个自动裁判程序,判定哪些字符串是可以获得“ 答案正确 ”的。

输入格式: 每个测试输入包含1个测试用例。第1行给出一个自然数n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过100,且不包含空格。

输出格式:每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出YES,否则输出NO。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100
int Scan(char * a);
int Check (char *a);

int main()
{
    int num;
    scanf("%d",&num);
    char str[N+1];
    for(int i=0;i<num;i++)
    {
            scanf("%s",str);
            Check(str);
            }
            return 0;
    }

int Check (char *str)
{
    int length=strlen(str);//the length of the string
    int precount=0,midcount=0,endcount=0,i=0;
    if(length<3)
    {
                printf("NO\n");
                return 0;
                }
    while(str[i]!='P'&&i<length)
    {
          if(str[i]=='A')//accumulate the number of A before P
          precount++;
          else
          {
              printf("NO\n");
              return 0;
              }
          i++;
          }
          i++;
    while(str[i]!='T'&&i<length)
   {
          if(str[i]=='A')//accumulate the number of A before P
          midcount++;
          else
          {
              printf("NO\n");
              return 0;
              }
          i++;
          }
          i++;
   while(str[i]!='\n'&&i<length)
   {
          if(str[i]=='A')//accumulate the number of A before P
          endcount++;
          else
          {
              printf("NO\n");
              return 0;
              }
          i++;
          }
   if(precount*midcount==endcount&&midcount!=0)
   {
   printf("YES\n");
   return 0;
   }
   else
   {
   printf("NO\n");
   return 0;
   }
}  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值