// One-star problem // Problem UVA101 The Blocks Problem /* This program is written by Prof. Chua-Huang Huang Department of Information Engineering and Computer Science Feng Chia University Taichung, Taiwan Disclaimer: The programming problem is downloaded from UVa Online Judge (https://uva.onlinejudge.org/). The program solution is provided for helping students to prepare Collegiate Programming Examination (CPE). The author does not guarantee the program is completely correct to pass UVa Online Judge platform or CPE examination platform. This program is not intended for a student to copy only. He/She should practice the programming problem himself/herself. Only use the program solution as a reference. The author is not responsible if the program causes any damage of your computer or personal properties. No commercial use of this program is allowed without the author's written permission. */ #include #include // Stack type definition with array implementation typedef struct { int data[24]; // Maximum 24 elements int top; // Top pointer } Stack; // Initial stack s. void initial_stack(Stack *s) { s->top = -1; } // Check if stack s is empty. int isempty(Stack s) { return s.top<0; } // Retrun the top element of stack s. int top(Stack s) { return s.data[s.top]; } // Push element e to stack s. void push(Stack *s, int e) { s->data[++s->top] = e; } // Pop the top element from stack s. int pop(Stack *s) { return s->data[s->top--]; } // Check whether e is in stack s. int find(Stack s, int e) { int i; for (i=0; i<=s.top; i++) if (s.data[i]==e) return 1; return 0; } // Print all elements of a stack from top to bottom. void print_stack(Stack s) { int i; for (i=0; i<=s.top; i++) printf(" %d", s.data[i]); // No trailing space is output for the last block. printf("\n"); } int main(void) { Stack line[24], temp; int n; int i; char cmd1[5], cmd3[5]; int cmd2, cmd4; int loc_a, loc_b, elem, step=0; scanf("%d", &n); // Input the number of bocks. for (i=0; i