2997 - I2P(II)2024_Yang_lab4 Scoreboard

Time

2024/04/26 16:20:00 2024/04/26 16:21:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13873 Dynamic Array 2
14280 Fraction Comparator

13873 - Dynamic Array 2   

Description

Based on the definition of Dynamic Array in Problem 13520 (nthu.edu.tw), you need to implement a dynamic array with the following functions:

  1. int& operator[](int): access data like using array. Users and main.cpp should/will not access the index which is greater or equal to size.
  2. void pushback(int x): append the element x
  3. void popback(void): pop the last element. Don't do anything if the array is empty.
  4. int back(void): return a copy of the last element. Return -1 if the array is empty.
  5. void clear(void): clear the array (set size to 0) so that the next pushbacks will place elements in data[0],data[1] and so on.
  6. int length(void): return the current size.
  7. void resize(void): double the capacity and copy the data.
  8. ~Darray(): destructor

Note that, two new functions void popback(void) and int back(void) are introduced in this problem.

// function.h

class Darray {
    public:
        Darray() {
            capacity = 100;
            size = 0;
            data = new int[capacity];
        };
        ~Darray();
        int& operator[](int);
        void pushback(int x);
        void popback(void);
        void clear(void);
        int length(void);
        int back(void);
        void print(void){
            if(this->size == 0){
                cout << endl;
            }
            else{
                for(int i=0; i<this->size; i++){
                    cout << this->data[i] << " ";
                }
                cout << endl;
            }
        };
    private:
        void resize(void); // double the capacity
        int *data;
        int capacity;
        int size;
};

Input

There are six kinds of commands:

  • “pushback integerA” represents adding an element with int value A at the end of the dynamic array.
  • “popback “ represents removing the element at the end of the dynamic array.
  • “clear” represents clearing the dynamic array.
  • “length” represents showing how many elements are in the dynamic array currently. 
  • “back” represents showing the element at the end of the dynamic array.
  • “print” represents showing the current content of the dynamic array.

Each command is followed by a new line character.

Output

The output should follow the instructions. 

("pushback", "popback" and "clear" will not print anything)

When the dynamic array is empty, you don’t need to print anything except a new line character.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13873.cpp

Partial Judge Header

13873.h

Tags




Discuss




14280 - Fraction Comparator   

Description

Your task is to create a fraction comparator that can handle the comparison of two fraction formulas that contain only addition.

In the provided code, you are advised to use a structure called "FractionList", which functions similarly to a linked list. When performing an addition, add the new fraction to the end of the list. Then, sums up all the fractions in each list and compares the result in the end.

This is a partial judge problem. Please review the provided code and refer to the sections labeled "TODO" in the function.h file for further details.

Important: Please select C++17 to submit your solution.

 

Input

The first line of the input contains an integer N, representing the number of test cases. (1 ≤ N ≤ 5 × 104)

Each of the following N lines represents a test case.
Each test case contains a sequence of fractions and operations formatted as follows:

<fraction_1> + ... + <fraction_n> <operator> <fraction_1> + ... + <fraction_m> ->  (5 ≤ n, m < 10)

Each fraction is written in the format <numerator>/<denominator>, where both numerator and denominator, as well as all numbers involved in calculations, fit within the range of a long long data type. The operators for each test case can be either "<", ">", "<=", or ">=".

 

Output

For each test case, output one line: If the given expression is true, output "True". Otherwise, output "False".

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

14280.cpp

Partial Judge Header

14280.h

Tags




Discuss