Home > Back-end >  C language array problems consult!!!!!!
C language array problems consult!!!!!!

Time:02-22

//1003 I want to pass! (20 points)

The question on the pta
#include
#include
Int main ()
{
Char c;
Int num.
The scanf (" % d ", & amp; Num);
While (getchar ()!='\ n');//to remove the scanf garbage data in the cache
Int I=0;//count is A position in A few number of
Char pri [num] [3];
for(i=0; I{
Int pos=0, the count [3]={0, 0};//, count [3]={0, 0} can't put the above
While ((c=getchar ())! )='\ n' {
If (c=='A') count (pos) + +;
Else if (c=='P' & amp; & Pos==0) pos=1;
Else if (c=='T' & amp; & Pos pos==1)=2;
The else break;
}
If (c=='\ n' & amp; & Pos==2 & amp; & The count [1] & amp; & The count [2]==count count [1] * [0]) {
Strcpy (pri [I], "YES");
}
The else {
Strcpy (pri [I], "NO");
}
If (c! )
='\ n'While (getchar ()!='\ n');//to clear away the rubbish in the getchar cache data
}
For (int j=0; JPrintf (" % s \ n ", pri [j]);
}
return 0;
}

I'm in the output problems



Four ge before the output should be only one YES, don't know why so many

CodePudding user response:

Modified as follows, for your reference:
 # include 
#include

Int main ()
{
Char c;
Int num.
The scanf (" % d ", & amp; Num);
While (getchar ()!='\ n');
Int I=0;
Char pri [11] [4].//char pri [num] [3]; Set the array error
for(i=0; I{
Int pos=0, the count [3]={0};//count [3]={0, 0};//, count [3]={0, 0} can't put the above
While ((c=getchar ())! )='\ n' {
If (c=='A') count (pos) + +;
Else if (c=='P' & amp; & Pos==0) pos=1;
Else if (c=='T' & amp; & Pos pos==1)=2;
The else break;
}
If (c=='\ n' & amp; & Pos==2 & amp; & The count [1] & amp; & The count [2]==count count [1] * [0]) {
Strcpy (pri [I], "YES");
}
The else {
Strcpy (pri [I], "NO");
}
If (c! )
='\ n'While (getchar ()!='\ n');
}
For (int j=0; JPrintf (" % s \ n ", pri [j]);
}

return 0;
}

//8
//PAT
//PAAT
//AAPATAA
//AAPAATAAAA
//xPATx
//PT
//Whatever
//APAAATAA
//YES
//YES
//YES
//YES
//NO
//NO
//NO
//NO
//please press any key to continue...
  • Related