1202 - CS I2P (II) 2017 Lee Mid2 Practice Scoreboard

Time

2017/05/05 15:30:00 2017/06/19 00:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

11428 - Copy a vector (Implement a vector 4)   

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

You are required to implement a vector with copy constructor and copy assignment operator.

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.cpp

Partial Judge Header

11428.h

Tags




Discuss




11429 - Iterator (Implement a vector 5)   

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.cpp

Partial Judge Header

11429.h

Tags




Discuss




11430 - Implement a list 1 (erase and insert)   

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

由於實際的code有做其他檢查,因此為了讓各位方便閱讀,請參考簡化版本的function.hmain.cpp(請點連結)

 

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 (erase, insert and S) are separated by a newline character ('\n').

Operation insert: following by a non-negative integer (insert position) and a non-negative integer (insert value, 0<=insert value<65535). Insert a node at insert position with insert value.

Operation erase: following by a non-negative integer (erase position). Erase a node at erase position.

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

如果不知道operator<<如何實作,可以看 main.cpp

Implement List (constructor, destructor, erase and insert), operator<<(std::ostream &,const List &lst).

Sample Input  Download

Sample Output  Download

Partial Judge Code

11430.cpp

Partial Judge Header

11430.h

Tags




Discuss