Home > Back-end >  By subject crazy I'm here for help
By subject crazy I'm here for help

Time:09-22

Title description

A certain city has A railway station, the track as shown, there are n cars from A direction into the station, the train sequence Numbers for 1 to n, your task is to determine whether to let them in A certain order in B and out of the station, the direction of the track to reorganization of the car, you can use hub in C, this is A can park any more car station, but the end caps, into the C must be out of the station module in the reverse order of the car, for example: the outbound order (5,4,1,2,3) is impossible, it is possible (5,4,3,2,1), for each carriage, once from A to C, you can't get back to A; Once from C to B, you can't come back to C, in other words, at any time, only two choices - A & gt; C and C - & gt; B,

Now give you arrange a 1 to n, please judge whether the subject describes a Possible, if is Possible, please output or output Impossible,
Input format

The first line of input t (1 & lt;=t<=10), said the number of test data set, the first line of an integer n (1 & lt;=n<=100), said n car, then a line with n integers, said the corresponding order,
The output format

For each set of data, the output of a line, if you can, then output "Possible", otherwise output "Impossible",
Input and output sample
Enter the # 1

2
5
1, 2, 3, 4, 5
5
1 2 3 4 5

Output # 1

Possible
Impossible
#include

using namespace std;

H is int stack [101] [101].

Bool AuA [11];

Int main ()
{
Int t, n, I, x, top=0, k=0;
Cin> t;
K=0;
For (x=0; X & lt; t; X++)
{
Cin> n;
for(i=0; i H [I];
For (I=1; i <=n; I++)
{
Stack [top]=I;
Top++;
While (top!=0)
{
If (stack [top 1]==h [k])
{
K++;
Top -;
}
The else break;
}
}
If (top==0 & amp; & K==n) AuA [x]=1;
K=0;
}
for(i=0; i {
If (AuA) [I] cout<" Possible "& lt; The else cout<" Impossible "& lt; }
return 0;
}
What's the problem with my code, please?

CodePudding user response:

Tracking after debugging skills learned to solve the problem,

CodePudding user response:

No bosses to help you , to write a code, but please explain it a little

CodePudding user response:

A breakpoint to debug, run step by step, look at each step is similar to the results of your calculations, will soon be able to find the problem;
  • Related