11419 - Using your vector (Implement a vector 3)   

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(請點連結)

 

This problem is similar to 11410 - Implement vector, but you have to do more things.

About how the instructions of vector work, please check above link.

This vector has an another operation, which is 

  • erase(): erases elements

You are required to do an employee statistic. Every employees has a name and an unique ID (starts from 0, increment after recruiting an employee).

You will have a class "God" which helps you construct class Employee and read the data members of Employee.

You have to implement

  • Vector (push_back, erase, reserve, destructor)
  • Employee(const std::string &name) (Don't forget to increase the ID_.)
  • void add_employee(Vector &vec,const std::string &name)
  • void print(const Vector &vec);
  • void quit(Vector &vec,unsigned id)
  • void quit(Vector &vec,const std::string &name)

You have to enable C++11 in this problem. (e.g. "g++ -std=c++11 ...")

Hint:

In C++, besides new expression, there is two operations simliar to new expression. One is called "operator new" (allocate memory) and the other is called "placement new" (construct object). You can think "new expression = operator new + placement new".

Here is some examples,

Input

Each input lines may be "recruit [name]", "quit 0 [name]", "quit 1 [id]", "reserve [size]", "capacity" or "size".

"recruit [name]" means push back the employee's [name] to the vector.

"quit 0 [name]" means erase employees from the vector if any employee's name is equal to the [name].

"quit 1 [id]" means erase employees from the vector if any employee's id is equal to the [id].

"reserve [size]" means reserve storage. (Increase the capacity of the container to a value that's greater or equal to new capacity. If new capacity is greater than the current capacity, new storage is allocated, otherwise the method does nothing.)

"capacity" means return the number of elements that can be held in currently allocated storage.

"size" means return the number of elements.

Output

Do the above operations. Print all elements in the vec after doing any operations. The print formate should be "employee_id employee_name\n".

Sample Input  Download

Sample Output  Download

Partial Judge Code

11419.cpp

Partial Judge Header

11419.h

Tags




Discuss