我是靠谱客的博主 受伤仙人掌,最近开发中收集的这篇文章主要介绍[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]!='';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.判断特殊情况是否正确

最后

以上就是受伤仙人掌为你收集整理的[PAT 乙级] 1003 我要通过! (20 分)的全部内容,希望文章能够帮你解决[PAT 乙级] 1003 我要通过! (20 分)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部