[PAT 乙级] 1003 我要通过! (20 分)


#include<iostream>
#include<string>
using namespace std;

int main(){
    int n=0;
    cin>>n;
    int flagerror=0;
    for(int j=0;j<n;j++)
    {
        flagerror=0;
        getchar();
        string str;
        cin>>str;
        int FlagP=0,FlagT=0,FlagA=0,countP=0,countT=0,countA=0;
        int i=0;
        for(;str[i]!='\0';i++)
        {
            if(str[i]!='A' && str[i]!='P' && str[i]!='T')
            {
                cout<<"NO"<<endl;
                flagerror=1;
                break;
            }
            if(str[i]=='P')
            {
                FlagP=i;
                countP++;
            }
            if(str[i]=='A')
            {
                FlagA=i;
                countA++;
            }
            
            if(str[i]=='T')
            {
                FlagT=i;
                countT++;
            }
        }
        if(flagerror==1)
        {
           continue;
        }
        
        if(countT>1 || countP>1||countA==0||countT==0||countP==0||FlagT==FlagP+1||FlagT<FlagP)
        {
            cout<<"NO"<<endl;
            continue;
        }
        
        int t=FlagT-FlagP-1;
        if(t>1)
        {
            if(FlagP==0)
            {
                ;
            }
            else{
                if(i-FlagT-1!=FlagP*t)
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            
        }
        if(t==1)
        {
            if(FlagP!=i-FlagT-1)
            {
                cout<<"NO"<<endl;
                continue;
            }
        }
        cout<<"YES"<<endl;
        
    }
}



错误:1.计算公式。为避免这种情况:画图、用文字写完公式再用字母表达。让代码中的字母与草稿纸上的字母表示的东西一样。
2.注意输出是否与代码中的一致。例如题目中是“答案正确、答案错误”,但输出是“YES”、“NO”。
3.判断特殊情况是否正确

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值