| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10993 | Polynomial class |
|
| 10998 | Stack |
|
| 12742 | Guess the gender |
|
Description
Create a class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent, e.g., the term 2x4 has the coefficient 2 and the exponent 4.
- Use a 51-element array, coefficients, of digits to store each coefficient.
- Use a integer variable, greatestPower, to store an exponent.
Provide public member functions that perform each of the following tasks:
- Adding two Polynomial.
- Subtracting two Polynomial.
- Multiplying two Polynomial.
- Printing coefficients of the Polynomial in descending order.
Note:
1. This problem involves three files.
- function.h: Class definition of Polynomial.
- function.cpp: Member-function definitions of Polynomial.
- main.cpp: A driver program to test your class implementation.
You will be provided with main.cpp, and asked to implement function.h and function.cpp.
function.h
main.cpp
2. For OJ submission:
Step 1. Submit only your function.cpp into the submission block.
(***Note that you don’t need to submit your function.h.)
Step 2. Check the results and debug your program if necessary.
Input
There are four lines.
The first two lines represent the greatest power and the corresponding coefficients of the first polynomial.
The last two lines represent the greatest power and the corresponding coefficients of the second polynomial.
Note that the coefficients are in descending order and each element is separated by a blank.
Output
Your program should print the coefficients of the sum, difference and product of these two polynomials in descending order, respectively.
Note that every answer should be followed by a new line character.
Sample Input Download
Sample Output Download
Partial Judge Code
10993.cppPartial Judge Header
10993.hTags
Discuss
Description
A stack is an abstract data type that serves as a collection of elements, where a node can be added to a stack and removed from a stack only at its top. Two principal operations can be used to manipulate a stack: push, which adds an element at the top, and pop, which removes the element at the top of the collection.

Let’s see how the stack data structure can be realized in C++.We have an approach to implement stack: linked list. Thus, we define a class as follows:
class List_stack {
public:
List_stack();
~List_stack();
void push(const int &);
void pop();
void print();
private:
ListNode *head;
ListNode *tail;
};
where List_stack implements the stack data structure
REQUIREMENTS:
Implement the constructor, destructor, push(), pop() and print() member functions of List_stack classes.
Note:
1.This problem involves three files.
- function.h: Class definitions.
- function.cpp: Member-function definitions.
- main.cpp: A driver program to test your class implementation.
You will be provided with main.cpp and function.h, and asked to implement function.cpp.
function.h
main.cpp
2.For OJ submission:
Step 1. Submit only your function.cpp into the submission block.
Step 2. Check the results and debug your program if necessary.
Input
There are three kinds of commands:
- “push integerA” represents adding an element with int value A at the top of the stack.
- “pop “ represents removing the element at the top of the stack.
- “print” represents showing the current content of the stack.
Each command is followed by a new line character.
Input terminated by EOF.
Output
The output should consist of the current state of the stack.
When the stack is empty, you don’t need to print anything except a new line character.
Sample Input Download
Sample Output Download
Partial Judge Code
10998.cppPartial Judge Header
10998.hTags
Discuss
Description
There is a game called "Guess the Gender",
the game rule is that given the number of people N and M hints,
a hint will be given as a pair of people's index,
represent that their genders are different,
in other words, a male and a female.
Your mission is to tell that if the given information is correct or not.
This is a partial judge problem,
and the problem is for exercising OOP,
so please use the given code to finish the problem,
and choose c++11 as the language on submission.
Since the code is using 'nullptr' instead of 'NULL', but you can just see 'nullptr' as 'NULL', they are kind of same.
To compile as c++11,
for those using codeblocks: `settings -> global compiler settings -> compiler flags -> check the option with [-std=c++11]`,
for those using devcpp: `Tools -> Compiler Options -> check 'Add the following commands when calling the compiler' -> add '-std=c++11'
for those using the command: `g++ -std=c++11 your_file.cpp`
ouo.
For Sample Input 1,
3 3
0 1
1 2
2 0
If person 0 is male, the first hint infers that person 1 is a female, then the second hint infer that person 2 is a male, but then the third hint contradicts.
If the person 0 is a female, it is not possible too.
So the answer should be "Not Possible".
4/26 supplement:
If you still have trouble in this problem after reading description and tracing codes, we show each step in the link, maybe it will be helpful for you :)
Input
The first line contains 2 numbers N, M,
N is the number of people and M is the number of hints.
Then the next M lines, each line contains 2 numbers X, Y,
represent the Xth person and Yth person have different gender.
The index starts at 0.
It is a guarantee that:
1 <= N <= 10^5,
1 <= M <= 10^6,
0 <= X, Y < N
Output
The output should be "Possible" if the given hint is correct,
or "Not Possible" if the given hint is not correct. (Without quotes)
Remember to add a newline character after the output.