2321 - I2P(II)2021_Kuo_hw3 Scoreboard

Time

2021/04/20 21:00:00 2021/05/04 13:20:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11410 Implement a vector 2
12273 Matrix
13172 Powers
13182 Twenty One

11410 - Implement a vector 2   

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

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.

 

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

There are seven 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
  • insert: inserts elements (If there is no capacity for new elements, the new capacity is max (old capacity + old capacity / 2, old capacity + count of inserting elements).) (If a vector has two elements, inserting three elements at position two means push back three times.) 
  • 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.)
  • resize: changes the number of elements stored (If the value of new size is greater than the value of old size, the value of new elements will be 0. If the value of new size is greater than the value of old capacity, the value of new capacity will be new size.)

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

Output

Implement Vector (constructor, push_back(), pop_back(), capacity(), size(), reserve(), resize(), insert() and destructor).

Sample Input  Download

Sample Output  Download

Partial Judge Code

11410.cpp

Partial Judge Header

11410.h

Tags




Discuss




12273 - Matrix   

Description

Create a class Matrix to represent an N * N matrix.

 

Provide public member functions that perform or derive:

     1) Matrix(const Matrix &);  // copy constructor

 

     2) Matrix &clockwise90();

Rotate a Matrix by 90° clockwise.

NOTE:

If a is a Matrix, the result of a.clockwise90() should be stored back into a. Remember to return the object itself for the use of operation concatenation, such as a.clockwise90().clockwise90(). (You can refer to member function “Matrix &operator=” in function.h.)

 

     3) Overload the stream extraction operator (>>) to read in the matrix elements.

 

    4)  Overload the stream insertion operator (<<) to print the content of the matrix row by row.

 

     5)  Default constructor

 

    6)  Destructor

 

    7)  Overload the operator (=) to assign value to matrix.

         Note that all of the integers in the same line are separated by a space, and there is a new line character at the end of each line.

 

Note:

1.  This problem involves three files.

  • function.h: Class definition of Matrix.
  • function.cpp: Member-function definitions of Matrix.
  • main.cpp: A driver program to test your class implementation.

You will be provided with function.h and main.cpp, and asked to implement 

 

2. For OJ submission:

       Step 1. Include function.h into function.cpp and then implement your function.cpp. (You don’t need to modify function.h and main.cpp)

       Step 2. Submit the code of function.cpp into submission block.

       Step 3. Check the results and debug your program if necessary.

Input

The first line has an integer N (1<=N<=50), which means the size of the matrix. The total number of elements in the matrix is thus N * N.

 

For the next N lines specify the elements of the matrix a. All of the integers in the same line are separated by a space.

Output

Your program should print the corresponding results followed by a new line character.

Sample Input  Download

Sample Output  Download

Partial Judge Code

12273.cpp

Partial Judge Header

12273.h

Tags




Discuss




13172 - Powers   

Description

This is a partial judge problem.

In this problem, you have to implement some power function in class special_power:

  • special_power(int n)  default constructor
  • int fpow(int x)  return xn % 880301
  • int fpow(int x, int m)  return xn % m
  • int fpow()  return 2n % 880301
  • string fpow(string s)  return sn
  • string fpow(string s, int m)  return sn % m

Note that n is a member in class special_power.

The definition of  sn

Repeat the elements of s n times, and connect them

For example:

  • abcd4 = aaaabbbbccccdddd
  • csst3 = cccssssssttt

The definition of sn % m:

Repeat the elements of s n times, and connect them.

If the lenth of sn is longer than m, ignore the remaining elements.

For example:

  • abcd4 % 10 = aaaabbbbcc
  • csst3 % 4 = cccs

Input

The input has only one line, contains three integer x, n, m and one string s.

For all testcase:

  • 1 <= x, m <= 109
  • 1 <= n <= 106
  • 1 <= |s| <= 1000
  • (1/6) 1 <= xn, 2n < m <= 880301, 1 <= |s| * n <= m
  • (1/6) 1 <= xn, 2n < m <= 880301
  • (1/6) 1 <= |s| * n <= m

Output

The output has five lines.

The 1st line, output the result of xn % 880301

The 2nd line, output the result of xn % m

The 3rd line, output the result of 2n % 880301

The 4th line, output the result of sn

The 5th line, output the result of sn % m

Sample Input  Download

Sample Output  Download

Partial Judge Code

13172.cpp

Partial Judge Header

13172.h

Tags




Discuss




13182 - Twenty One   

Description

21 movie review & film summary (2008) | Roger Ebert

After watching the movie 21, Kuo is curious about casino.

There is a casino which opens N days in this month.

There will be two kind of events in a day.

  1. Guest <Someone> <Money> <Skill>. It means <Someone> enter the casino with <Money> money. <Someone> are their names, <Money> is the amount of money with them, and <Skill> is how well they play. If <Someone> are already in the casino or are blacklisted, ignore this event.
  2. Win <Someone> <Money>. It means <Someone> win <Money> money in a play from the casino. <Money> may be positive or negative. If <Someone> are not in the casino or are blacklisted, ignore this event.

 

Whenever someone enter the casino, they have to pay T entrance fee to the casino. The enterance fee may change every day.

Whenever one become bankrupt, they will be kicked out of the casino and be blacklisted.

If the amout of money someone win in a play exceed (that is, >) twice of their <Skill>, they will be seen as cheaters, kicked out of the casino, and blacklisted. (The casino still has to pay the money they win to them.)

Someone blacklisted are not permitted to enter the casino. In particular, when someone blacklisted wants to enter the casino, they won't be charged the enterance fee.

Note: If someone have to pay X money but they only have Y money where Y <= X, they will only pay Y money and become bankrupt.

At the end of each day, everyone will leave the casino.

 

Please help Kuo-chan find how much income the casino gets in this month and who are blacklisted.

Input

The first line of the input contains a number — the number of days in this month.

The following contains blocks.

The first line of each block is Casino Q T — it means there will be events and the entrance fee is T this day.

The next lines is one of the following:

  1. Guest <Someone> <Money> <Skill>
  2. Win <Someone> <Money>

 

N <= 1000, Q <= 100. 

There will be at most 1000 different people come to the casino; that is, there are at most 1000 people with different names. Therefore, there will be at most 1000 people blacklisted.

All number is within the range of int.

Output

You should print a number in the first line — how much income the casino gets in this month.

If there are people blacklisted in this month, you should output their names in lines in the order they get blacklisted.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13182.cpp

Partial Judge Header

13182.h

Tags




Discuss