2510 - I2P(II)2022_Kuo_hw3 Scoreboard

Time

2022/04/15 15:10:00 2022/04/26 13:20:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11422 Shape
12286 Matrix
13172 Powers
13182 Twenty One
13464 Compare strings or characters

11422 - Shape   

Description

Warning: You are not allowed to use malloc and free

Following the lecture slide :

Giving a bass-class Shape and 3 derived class : Triangle, Rectangle, Circle

You need to calculate the area and the perimeter of each shape.

note : You need to do some basic check: if the given information cannot form a shape (e.g. height of the rectangle is negative number....etc), then the area and perimeter would be both 0)

Input

There are only 3 shapes in this problem :

  • Triangle, following by its 3 edges. (e.g. Triangle 3 4 5)
  • Rectangle, following by its width and height. (e.g. Rectangle 5 7)
  • Circle, following by its radius and the value of pi. (e.g. Circle 2 3.14)

Output

Ouput the total area and perimeter of all the shapes.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11422.cpp

Partial Judge Header

11422.h

Tags




Discuss




12286 - 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) Overload the stream extraction operator (>>) to read in the matrix elements.

 

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

 

     4)  Default constructor

 

    5)  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

12286.cpp

Partial Judge Header

12286.h

Tags

matrix



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 length 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

Notice: Please use C++11 or above to submit this problem!

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




13464 - Compare strings or characters   

Description

Compare to C, it's much more easy for us to compare two strings by means of using relational operators directly. Nevertheless, there are still something inconvinient.For instance, we could compare a single character (which is regarded as 1-length string) with a string in Python, yet not in C++ since the concering operators is not overloaded.

On the other hand, there is a brand new operator called three way comparison coming with C++20, which return \(1\) if the left hand side is greater than the right hand side, \(0\) if the two sides are equal, \(-1\) otherwise.

So in this partial-judged problem, your task is to implement the function cmp() to stimulate the behavior of that operator on strings and characters and extend the feature. cmp() should accept the following 7 sort of parameters:

  1. Just compare the two strings
  2. Compare the first n characters of two strings
  3. Compare the character and the string, considering the character as 1-lengthed string
  4. Similar with the above, only different in the order of the parameters
  5. Compare the character and the n-th character of the string
  6. Similar with the above, only different in the order of the parameters
  7. Just compare the two characters

The first 4 ones are about comparing string, whereas the last 3 ones are just about characters.

 

Input

Since this problem is judged partially, you needn't be concerned about the format of input.

In case your're interested, there at most 100 lines in a test file. Each line contains two string, \(s, t\) and a integer \(n < \min\{|s|, |t|\}\).

Output

Since this problem is judged partially, you needn't be concerned about the format of output.

In case your're interested, for each line input, print the result of comparing \(s\) and \(t\), the first \(n\) characters of \(s\) and \(t\), \(s\) and the last character of \(t\), the first character of \(s\) and \(t\), the \(n^{th}\) character of \(s\) and the last character of \(t\), the first character of \(s\) and the \(n^{th}\) character of \(t\), the last character of \(s\) and the first character of \(t\) in a line separated by spaces and ended with a new line character.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13464.cpp

Partial Judge Header

13464.h

Tags




Discuss