1003 我要通过! (20分)
写的比较繁琐,再来梳理一下思路
源码:
#include<iostream>
using namespace std;
int main()
{
int i;
int a[10];
cin>>i;
getchar();
for(int m=0;m<i;m++)
{
int left=0;
int medium=0;
int right=0;
int table1=0;
int table2=0;
int table3=0;
int Pnum=0;
int Tnum=0;
int error=0;
for(char s;s=getchar(),s!='\n';)
{
if(s=='A')
{
table3=1;
if(table1==0&&table2==0)
left++;
else if(table2==1&&table1==1)
right++;
else if(table1==1&&table2==0)
medium++;
else if(table1==0&&table2==1)
error=1;
}
else if(s=='P')
{
Pnum++;
table1=1;
}
else if(s=='T')
{
Tnum++;
table2=1;
}
else
error=1;
}
if(Pnum==1&&table3==1&&Tnum==1&&left*medium==right&&error==0)
a[m]=1;
else
a[m]=0;
}
for(int j=0;j<i;j++)
{
if(a[j]==1)
cout<<"YES";
else
cout<<"NO";
cout<<endl;
}
}
思路梳理:
1.首先是参考了此位博主的案例了解了基本思路
2.’\0’是字符串的最后结尾标志,’\n’是换行符。因为将这个搞混了 所以浪费了不少时间
3.最后一个低级错误 int Pnum,Tnum=0;
这条语句中只将Tnum的值赋0,并未将Pnum的值赋0。
正确写法为int Pnum=0,Tnum=0;