1337 - CS I2P (II) 2017-2 Lee Quiz4 Scoreboard

Time

2017/11/17 13:20:00 2017/11/17 14:50:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11420 Implement a vector 1
11462 cppreference
11677 Implement a list 4 (back and remove)

11420 - Implement a vector 1   

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

Vectors are sequence containers representing arrays that can change in size.

The storage of the vector is handled automatically, being expanded and contracted as needed. Vectors usually occupy more space than static arrays, because more memory is allocated to handle future growth. This way a vector does not need to reallocate each time an element is inserted, but only when the additional memory is exhausted.

REQUIREMENTS:

Implement the push_back(), pop_back(), reserve() and destructor member functions of Vector classes.

Note:

If the value of size is equal to the value of capacity, and you need to change the value of capacity (reallocate memory) when you push_back a new element. The rule of increasing capacity is: new capacity = max(old capacity + 1, old capacity * 3).

The constructor of vector will not create an array (which means size and capacity is 0).

Input

here are five kinds of commands:

  • pop_back: removes the last element
  • push_back: adds an element to the end
  • capacity: returns the number of elements that can be held in currently allocated storage
  • size: returns the number of elements
  • reserve: reserves storage (Increase the capacity of the container to a value that's equal to new capacity. If new capacity is greater than the current capacity, new storage is allocated, otherwise the method does nothing.)

Each commands is followed by a new line character ('\n').

Output

The output should consist of the current state of the vector.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11420.cpp

Partial Judge Header

11420.h

Tags




Discuss




11462 - cppreference   

Description

版本:

20180311

 

使用說明:

請下載code或header(兩個是同個檔案)

把附檔名從.cpp改成.zip

解壓縮後

reference>en>cpp.html

即可看到官方文件

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

11462.cpp

Partial Judge Header

11462.h

Tags

CPP Reference



Discuss




11677 - Implement a list 4 (back and remove)   

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 (push_back, remove and show) are separated by a newline character ('\n').

Operation push_back: following by a non-negative integer (insert value, 0<=insert value<20). Push a node at the end position with insert value.

Operation remove: following by a non-negative integer (remove value, 0<=insert value<20). Erase all nodes which data is equal to remove 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, destructor, push_back and remove) and operator<<(std::ostream &os,const List &lst).

Sample Input  Download

Sample Output  Download

Partial Judge Code

11677.cpp

Partial Judge Header

11677.h

Tags




Discuss