13896 - Darray stack for postfix calculation (4/10)   

Description

The problem “Darray stack” is splitted into 2 subproblems:

 
 Comment
  1. Darray & stack implementation (4/10)
  2. Postfix expression calculation using stack (6/10)

You should solve this subproblem first.


In this subproblem, you have to implement a stack class, Darray_stack, which uses the Darray class you have implemented in "13873 - Dynamic Array 2" as its internal representation.

Here is the structure of Darray_stack:

class Darray_stack{
    public:
        Darray_stack();
        void operator << (const int&);
        void operator >> (int&);
        int size(){
            return arr.length();
        }
    private:
        Darray arr;
};

You have to implement 3 public member functions for Darray_stack:

  1. Darray_stack(): the constructor
  2. void operator << (const int&): overloads << to push an element onto the stack
  3. void operator >> (int&): overloads >> to pop an element from the stack and store it at the right operand

To compile your code:

  • Your function.cpp should include function.h and contain the implementation of both Darray (copied from your code in "13873 - Dynamic Array 2") and Darray_stack. Our main.cpp would run the function ‘verify_code’ to test whether your implementation is correct.
  • Please use C++17.

Input

The first line is a string which only contains digits, representing the input of the verify function.

The second line is a postfix expression.

Constraints:

All numbers in the expression are nonnegative and are less than or equal to 100.

The length of the expression is no more than 250.

The length of the verify input code is no more than 10000.

The operators would only be '+', '-' or '*'.

It is guaranteed the numbers won't exceed 10during the whole calculation process.

Output

Output the verify code.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13896.cpp

Partial Judge Header

13896.h

Tags




Discuss