3=====
\
2======- & gt; Move
You have seen on some data structure teaching material "column" train scheduling (haven't seen it doesn't matter, of course), today, we're going to practice a train scheduling, of the following controls at the top of the ASCII character figure, problem description is as follows:
There are three parallel train tracks (1, 2, 3), and 1-3 and 2-3 two connection orbit, a list of existing car parked in orbit, 1 please use connect two orbit and orbit, 3 moving carriage according to the requirements of the order to 2 orbit, the rule is:
Every time transfer 1 carriage;
In no. 1 rail cars or after 1-3 connection way to orbit 3 (the action as "1 - & gt; Article 3 "), or after two connected directly into 2 orbits (this action as "1 - & gt; 2 ");
Once the car into the no. 2 orbit, can not remove the track again;
In 3 orbital compartment, only after 2-3 connection way to orbit 2 (this operation for "3 - & gt; 2 ");
Obviously, any car can't span across, or bypass other car to mobile,
Parking sequence for a given 1, if after order scheduling can achieve 2 track requirements, give an operation sequence; If you can't, ask users Are (you Are) you (is) $(christopherkaeding) me ()?
Input format:
Two lines composed of capital letters is not empty string, the first line says stop at no. 1 car on the tracks from left to right, the second line indicates that car stopped to 2 orbit into the sequence (the second line of input sample 1 CBA said in 2 rail car park is ABC from left to right, because C into the first, so in most the right side), two lines of the same string length and no more than 26 (26 because only capital letters), each letter represents a carriage, subject to ensure that the same inline letters don't repeat same set and two rows of letters,
The output format:
If successfully scheduling and give the shortest sequence of operations, each operation of a line, the so-called "shortest", namely if 1 - & gt; 2 can complete the scheduling, don't through 1 - & gt; 3 and 3 - & gt; 2, if not scheduling, output "you $me?"
Input the sample 1:
ABC
The CBA
The output sample 1:
1 - & gt; 3
1 - & gt; 3
1 - & gt; 2
3 - & gt; 2
3 - & gt; 2
Enter the sample 2:
ABC
CAB
The output sample 2:
Are you kidding me?
Code:
#include
#include
#include
# define MAX 100
# define LEN sizeof (StackNode)
Typedef struct CH
{
char ch;
Struct CH * next;
} StackNode;
Typedef struct
{
StackNode * top;
} Stacktop;
Int DY (Stacktop * S);
Void Push Stacktop * S, char (a);
Pop (Stacktop is void * S);
Int the Empty (Stacktop * S);
Char read (Stacktop * S);
Int main ()
{
Stacktop * S=(Stacktop *) malloc (sizeof (Stacktop));//please don't forget to initialize!!!!!!!!!!
S - & gt; Top=NULL;
DY (S);
return 0;
}
Int DY (Stacktop * S)
{
Stacktop * list1=(Stacktop *) malloc (sizeof (Stacktop));
Stacktop * list2=(Stacktop *) malloc (sizeof (Stacktop));
Char a (MAX), b (MAX);
Int I=0, j, x;
Int Po (MAX);
List1 - & gt; Top=NULL;
List2 - & gt; Top=NULL;
The scanf (" % s ", a);
The scanf (" % s ", b);
X=strlen (a) - 1;
J=0;//strlen (b) - 1;
While (a [I])
{
If (i
Push (S, a [I]);
Po [I]=13;
}
Else if (I==x)
{
Push (list1, a [I]);
Po [I]=12;
//printf (" list: % c \ n ", read (list1));
If (b [j++]!=read (list1)) {printf (" you $to me? \n"); return 0; }
}
i++;
}
While (S - & gt; The top!=NULL)
{
Push (list1, read (S));
If (b [j++]!=read (list1)) {printf (" you $to me? \n"); return 0; }
//printf (" list: % c \ n ", read (list1));
Pop (S);
Po [I]=32;
i++;
}
For (x=0; x{
Printf (" % d - & gt; % d \ n ", Po/10 [x], Po [x] % 10);
}
return 1;
}
Int the Empty Stacktop * (S)//is Empty stack
{
The return of S - & gt; Top==NULL;
}
Void Push Stacktop * S, char (a)//into the stack
{
StackNode * p=(StackNode *) malloc (LEN);
P - & gt; Ch=a;
P - & gt; Next=S - & gt; Top;
S - & gt; Top=p;
}
Char read Stacktop * (S)//read
{
The return of S - & gt; Top - & gt; Ch;
}
Pop (Stacktop is void * S)//the stack
{
StackNode * p=S - & gt; Top;
If (S - & gt; The top!=NULL) {
S - & gt; Top=p - & gt; Next;
Free (p); }
}
Save the children!
CodePudding user response:
S equivalent to 3 track, list1 is equivalent to no. 2, when the input string with a character is entered orbit, 2 again to join the characters of all the 3 track 2 orbit, as long as you have to enter orbit 2 determine the input of the second is the first j a character string, different means can't dispatch, why have a PTA test point anywayCodePudding user response:
Convenient send the title link, I verify my ideasCodePudding user response:
https://pintia.cn/problem-sets/1239445850577838080/problems/1239707569174749184CodePudding user response: