| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10993 | Polynomial class |
|
| 10998 | Stack |
|
| 13178 | Band Ya Rou Ze - Reverse Classtarburst |
|
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
This is a partial judge problem OwO
Here is an idea to solve 13136 - Band Ya Rou Ze - Reverse: For each row, using a linked list to record all the people. And for each node just record the adjacent node(s) of it rather than the next node and/or the previous node. By using this kind of linked list, all types of moving could be implement in .
In this problem, you need to complete the code which implements the above idea with C++ class. A little difference with 13136 - Band Ya Rou Ze - Reverse is that there are tasks in this problem and the constraint of number of people is changed.
Note
In the following code, nullptr is just like NULL in C. You could treat them as the same.
But nullptr is only available in C++11 and beyond. So compiling/submitting your code in C++11 or beyond.
Partial Code
main.cpp
#include <iostream> #include <string> #include "function.h" using namespace std; int main() { /* I/O optimization */ ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while(T--) { int n; cin >> n; List *row = new List[n + 1]; for(int i=1;i<=n;i++) { int sz; cin >> sz; if(sz > 0) { string s; cin >> s; row[i].init(s); } } int q; cin >> q; while(q--) { int type, a, b; cin >> type >> a; if(type != 4) cin >> b; if(type == 1) { row[b].merge(row[a], row[b]); row[a].clear(); } else if(type == 2) { row[b].merge(row[b], row[a]); row[a].clear(); } else if(type == 3) { row[a].swap(row[b]); } else { row[a].reverse(); } } for(int i=1;i<=n;i++) row[i].output(); delete[] row; } return 0; }
function.h
#ifndef FUNCTION_H #define FUNCTION_H class Node { private: char instrm; Node *neighbors[2]; /* disconnect the link with a specific node */ void unLink(Node *delNeighbor) { /* you could consider "nullptr" as "NULL" */ if(neighbors[0] == delNeighbor) neighbors[0] = nullptr; if(neighbors[1] == delNeighbor) neighbors[1] = nullptr; } public: Node() {} Node(char instrument) : instrm(instrument), neighbors{nullptr, nullptr} {} /* connect this node with another node */ void link(Node *newNeighbor) { neighbors[(neighbors[0] == nullptr ? 0 : 1)] = newNeighbor; } void output(Node *prevNode) { std::cout << instrm; for(int i=0;i<2;i++) if(neighbors[i] != nullptr && neighbors[i] != prevNode) neighbors[i]->output(this); } /* TODO: destructor for this class */ ~Node(); }; class List { private: Node *head, *tail; // point to the first and the last node of this linked list public: List() : head(nullptr), tail(nullptr) {} /* TODO: using a string to initialize this linked list */ void init(std::string s); /* TODO: make this linked list be a new linked list which is merged from two linked list */ void merge(List &front, List &back); void clear() { head = tail = nullptr; } /* TODO: exchange this linked list with another linked list; try to use std::swap! */ void swap(List &swapList); /* TODO: reverse the order of this linked list */ void reverse(); void output() { if(head != nullptr) head->output(nullptr); std::cout << '\n'; } /* TODO: destructor for this class */ ~List(); }; #endif
Input
The very first line contains one integer – the number of tasks.
The first line of each task contains one integer – the number of rows.
Then lines follow. The
-th line of each task first contains one integer
– the number of people in the
-th row. If there are some people in the row, a space character and
characters cij are followed where
is the musical instrument played by the
-th people in the
-th row. The sum of all the
in one task is less than or equal to
.
The next line contains one integer – the times they need to move.
Then lines follow. The
-th line of each task contains two integer
. If
isn't equal to 4, then a integer
follows
– they are the corresponding information for each moving.
It's guaranteed that:
- The 1st testcase must be identical to the Sample #1 below
Output
For each task, output one line which represents all the musical instrument played in every row after all the moving.
If there is no people in some row, just output an empty line.
Note: there are two sample below. "# Sample Input 1/2" and "# Sample Output 1/2" are not the part of input and output.
They are just for marking that the following content corresponds to which sample.