| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11431 | String Operation |
|
| 12248 | Queue |
|
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.
Sample Input Download
Sample Output Download
Partial Judge Code
11431.cppPartial Judge Header
11431.hTags
Discuss
Description
A queue is an abstract data type that serves as a collection of elements, where nodes are removed only from the head of the queue and are inserted only at the tail of the queue. Two principal operations can be used to manipulate a queue: enqueue, which inserts an element at the tail, and dequeue, which removes the element at the head of the collection.

Let’s see how the queue data structure can be realized in C++.We have an approach to implement queue: linked list. Thus, we define a class as follows:
class List_queue {
public:
List_queue();
~List_queue();
void enqueue(const int &);
void dequeue();
void print();
private:
ListNode *head;
ListNode *tail;
};
where List_queue implements the queue data structure.
REQUIREMENTS:
Implement the constructor, destructor, enqueue(), dequeue() and print() member functions of the List_queue class.
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.
Input
There are three kinds of commands:
- “enqueue integerA” represents inserting an element with int value A at the tail of the queue.
- “dequeue” represents removing the element at the head of the queue.
- “print” represents showing the current content of the queue.
Each command is followed by a new line character.
Input terminated by EOF.
There exist a testcase that over 100000+ operations.
Output
The output should consist of the current state of the queue.
When the queue is empty, you don’t need to print anything except a new line character.