Assumes that the stack sequence 1 2 3 4... N, then the stack sequence is an arrangement of 1 to n, assuming that expressed in P into the stack operation, using qq show stack operation, the stack operation process can be expressed as a sequence composed of P and Q, for a given stack sequence, should how to operate to get?
Enter
Input consists of several lines, each line is a group by the space interval integer, the first integer is the length of the sequence of n (n is not more than 1000), followed by the arrangement of a 1 to n,
O
For each line of input, calculate the corresponding stack operation sequence, and output the operation sequence, if can not output the sequence, shall not be operated in the location of the output "error",
The sample input
4 1 2 3 4
4 4 3 2 1
4 4 1 2 3
4 1 2 3 4
Sample output
PQPQPQPQ
PPPPQQQQ
PPPPQ error
PPPQ error
this is the uncompleted code I wrote but I don't know what the problem is the thinking of QAQ so can't write ideas & amp; Source
# include
using namespace std;
# define Maxsize 1003
Typedef struct {
The int data [Maxsize];
Int top;
} SqStack;
Void InitStack (SqStack & amp; S) {
S.t op=1;
}
Void Push (SqStack & amp; S, int x) {
If (s.t op==Maxsize - 1) return;
S.t op++;
Spyware doctor ata [s.t op]=x;
}
Int Pop (SqStack & amp; S, int x) {
If (s.t op==1) {
Printf (" error ");
return 0;
}
X=s.d. ata [s.t op];
S.t op -;
Printf (" % d ", x);
return 1;
}