11452 - Str with functional node
|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
| Case 2 |
1 sec |
32 MB |
| Case 3 |
1 sec |
32 MB |
| Case 4 |
1 sec |
32 MB |
| Case 5 |
1 sec |
32 MB |
| Case 6 |
1 sec |
32 MB |
| Case 7 |
1 sec |
32 MB |
| Case 8 |
1 sec |
32 MB |
| Case 9 |
1 sec |
32 MB |
| Case 10 |
1 sec |
32 MB |
Description
In this problem, we define a custom string that is a list linking some nodes.
The involved classes are explained as follows.
A. Definition of class Node
- An abstract base class that declares pure virtual func() and clone() methods
- clone() will return a new object according to its derived class
- Has a pointer (next)
B. Definition of class CharNode
- A derived class of Node
- Contains a char (text)
- func() outputs “text”
C. Definition of class RepeatNode
- A derived class of Node
- Contains an integer (times)
- If next != NULL, func() will call next->func() “times” times.
D. Definition of class Str
- Maintain a list of some Nodes
- Can access the Node by index
- Can attach a Node
- Can return how many Nodes it contains by length()
Note:
You are asked to implement
- void CharNode::func()
- void RepeatNode::func()
- Str::Str(const Str &s)
- void Str::attach(Node *ptr)
- Attach the input Node to the end of Str
- Note: you can simply assign ptr to tail->next if the Str is not empty
- int Str::length()
- Node *Str::operator[](int idx)
- Return the address of the idx-th Node
Input
First part
An integer n that means the number of Strs.
And then, n lines that are the inputs of Strs.
Second part
Four kinds of commands.
- c n m: delete m-th Str and copy n-th Str to position m
- a n l m: duplicate the l-th Node of n-th Str and attach it to the end of m-th Str
- s m: show m-th Str
- l m: output the length of m-th Str
Output
The output depends on the commands.
Partial Judge Code
11452.cpp
Partial Judge Header
11452.h
Tags