| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10998 | Stack |
|
| 11431 | String Operation |
|
Description
A stack is an abstract data type that serves as a collection of elements, where a node can be added to a stack and removed from a stack only at its top. Two principal operations can be used to manipulate a stack: push, which adds an element at the top, and pop, which removes the element at the top of the collection.

Let’s see how the stack data structure can be realized in C++.We have an approach to implement stack: linked list. Thus, we define a class as follows:
class List_stack {
public:
List_stack();
~List_stack();
void push(const int &);
void pop();
void print();
private:
ListNode *head;
ListNode *tail;
};
where List_stack implements the stack data structure
REQUIREMENTS:
Implement the constructor, destructor, push(), pop() and print() member functions of List_stack classes.
Note:
1.This problem involves three files.
- function.h: Class definitions.
- function.cpp: Member-function definitions.
- main.cpp: A driver program to test your class implementation.
You will be provided with main.cpp and function.h, and asked to implement function.cpp.
function.h
main.cpp
2.For OJ submission:
Step 1. Submit only your function.cpp into the submission block.
Step 2. Check the results and debug your program if necessary.
Input
There are three kinds of commands:
- “push integerA” represents adding an element with int value A at the top of the stack.
- “pop “ represents removing the element at the top of the stack.
- “print” represents showing the current content of the stack.
Each command is followed by a new line character.
Input terminated by EOF.
Output
The output should consist of the current state of the stack.
When the stack is empty, you don’t need to print anything except a new line character.
Sample Input Download
Sample Output Download
Partial Judge Code
10998.cppPartial Judge Header
10998.hTags
Discuss
Description
Given a set of strings, perform the operations according to the following commands.
Commands: (n will not be equal to m)
s n m:
Swap the nth string and the mth string.
i n m:
Insert the mth string at the tail of the nth string.
si n m:
Swap the specified strings first, and then insert.
is n m:
Insert first, and then swap the two specified strings.
t n m:
If the nth string is equal to the mth string, do i n m. Otherwise, do s n m.
e:
Exit.
Note:
You will be provided with main.cpp and function.h, and asked to implement function.cpp including
Str::Str(char*);
Str::Str(const Str &);
bool Str::operator==( const Str &) const;
Input
The first line is an integer N indicating the number of input strings.
The following N lines each contains one input string.
Starting from the N+2th line will be a sequence of commands.
Output
Output the final result of the input strings.