| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11428 | Copy a vector (Implement a vector 4) |
|
| 11429 | Iterator (Implement a vector 5) |
|
| 11685 | Implement a list 5 (copy) |
|
Description
You must follow the rules as below:
1. do not use any static variables
2. do not use any variables which is not inside a function
3. only new, operator new, delete and operator delete are allowed to allocate or deallocate memory
The main function will create two empty vector which object type is Shape. The Shape calss has a Shape_impl pointer, and when you copy, you need to copy class Shape_impl instead of Shape_impl pointer in class Shape.
You should write three class (Rectangle, Square and Circle) to inhert Shape_impl, and these class also need to have copy constructor or copy assignment operator.
Please refer to function.h for detail.
Input
The input will have eight command.
Note: shape will look like rect length width, squa length and circ radius( the area of circle is radius*radius*3.14)
- p num shape: push_back a shape in vec[num]( vec[num] is vec[0] or vec[1])
- e num begin end: erase the shape between begin and end in vec[num] (erase vec[num][begin]~vec[num][end-1])
- i num pos count shape: insert #count shape into vec[num] in position pos
- c num: print vec[num].capacity()
- s num: print vec[num].size()
- copy num num2: copy vec[num2] to vec[num]
- sort num: sort the vec[num] (compare the area of shape)
- area num: print the total area in vec[num]
Output
Please complete
- class Rectangle, class Square, class Circle (pi will be 3.14)
- function: Shape_impl* new_rect, Shape_impl* new_squa, Shape_impl* new_circ
- function: Shape_impl* copy_Shape_impl, void delete_Shape_impl
- operator: bool operator<(const Shape_impl &,const Shape_impl &); note: (true return 1, false return 0)
- operator: std::ostream& operator<<(std::ostream &,const Shape_impl &);
- Vector function(push_back, erase, reserve, insert, ~Vector()) note: you can use the class vector you write in the previous homework. (you should modify erase function)
- Vector copy constructor (Vector(const Vector &)) and copy assignment operator (Vector& operator=(const Vector &))
Note: When you use vector copy constructor, e.g. oj::Vector temp(vec[num2]), temp's capacity will as same as vec[num2]
When you use vector copy assignment operator, e.g. vec[num]=temp, vec[num]'s capacity will be max(vec[num].capacity(), temp.capacity())
If you want to know the rule of size and capacity, you can see 11410 - Implement vector.
When you input a command, the output will show the vec[0] and vec[1].
Sample Input Download
Sample Output Download
Partial Judge Code
11428.cppPartial Judge Header
11428.hTags
Discuss
Description
Warning: You are not allowed to use:
1. any static variables
2. any variables which is not inside a function
3. malloc and free
But this time, you have to implement a intact Iterator.
member function of Vector:
erase: erase elements which is pointed by begin to end ([begin,end)). While begin is equal to end, do not erase any elements.
insert: insert elements at position pos. The insert elements are from iterators which are pointed by begin to end ([begin,end)). While begin is equal to end, do not insert any elements.
Input
Input is a sequence of non-negative integer (smaller than 100).
Output
Complete Vector (constructor, destructor, begin, end, erase, insert, push_back and reserve) and Iterator (all data member functions).
Sample Input Download
Sample Output Download
Partial Judge Code
11429.cppPartial Judge Header
11429.hTags
Discuss
Description
You must follow the rules as below:
1. do not use any static variables
2. do not use any variables which is not inside a function
3. only new, operator new, delete and operator delete are allowed to allocate or deallocate memory
4. memory usage limit: 2048 byte
You are required to implement a list.
You have to enable C++11 in this problem. (e.g. "g++ -std=c++11 ...")
Input
The input consist of a number of operations. Each operations (copy ctor, copy assign, back, front, clear, erase, insert and show) are separated by a newline character ('\n').
Operation copy ctor: following by a non-negative integer (which list calls the copy constructor).
Operation copy assign: following by a non-negative integer (which list calls the copy assignment operator).
Operation back: Print the value of last node.
Operation front: Print the value of first node.
Operation clear: Erase all nodes.
Operation erase: following by a non-negative integer (erase position). Erase a node at erase position.
Operation insert: following by a non-negative integer (insert position) and a non-negative integer (insert value, 0<=insert value<20). Insert a node at insert position with inserted value.
Operation show: print the value of all nodes in the list. Print a whitespace character (' ') after printing the value of nodes. If the list is empty, do not print anything.
Output
Implement List (constructor, copy constructor, copy assignment operator, destructor, back, front, clear, erase and insert) and operator<<(std::ostream &os,const List &lst).