Description
"int" is too small to contain large odd numbers!
That's why you decided to implement your own data type, BigOdd.
You need to implement 5 basic functions:
1. Constructor. It is initalized by a string representing a non-negative integer without leading zeroes, e.g., "123".
2. Destructor.
3,4. ++x, x++, the prefix increment and postfix increment operators, respectively. Note that, since this is a BigOdd data type, whenever it increments, it will be the least odd number that is greater than the current value. For example, ++3 => 5, ++2 => 3.
5: char* to_s(): returns a duplicate of the number in char*, e.g., "123".
Input
The first line contains an integer T, representing the number of testcases that follow.
For each testcase, a non-negative integer less than pow(10, 1023) is given in the first line.
An integer Q follows, representing the number of operations regarding the testcase.
Q lines follow, each in the form of "B++" or "++B", the effect of which is described in the problem.
Output
For each operation, print the result in one line, without leading zeroes.
Sample Input Download
Sample Output Download
Partial Judge Code
12716.cppPartial Judge Header
12716.hTags
Discuss
Description
You need to implement the following functions for a binary search tree data structure:
BST(); // constructor, does what needs to be done when created
~BST(); // destructor, doest what needs to be done when destroyed
void insert(int v); // insert value v
string inorder(); // returns a string representing the values in the inorder traversal, separated by a space
There is only one private member "Node *root" in BST. The definition of Node is as follows:
struct Node {
int val;
int cnt; // occurence of value
Node *lc; // left child
Node *rc; // right child
Node(int v) : val(v), lc(nullptr), rc(nullptr) {} // init to null when created
};
Note that duplicate values may exist at the same time in the data structure
Input
Q
OP_1
OP_2
...
OP_Q
Where Q is an integer representing the number of operations. Q lines follow.
OP_i is the i'th operation, and it may be one of the two following forms:
0 V
1
Where "0 V" will need you to insert V into the BST, and "1" needs you to print the inorder traversal. The operations has to be accomplished in the order they are given.
1 <= Q <= 2000
0 <= V <= 10^9
Output
For each operation "1", print the inorder traversal in a line.