| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10998 | Stack |
|
| 11417 | String Operation |
|
| 11897 | Matrix Multiply |
|
| 11915 | Vector |
|
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
Given a set of strings, perform the operations according to the following commands, and output the final result of the given set of strings.
Commands:
s n m: Swap the nth string and the mth string.
i n m: Insert the mth string at the tail of the nth string.
si n m: Swap the specified strings first, and then insert.
is n m: Insert first, and then swap the two specified strings.
e: Exit.
Consider a set of strings:
ab
cd
ef
And a sequence of commands:
s 0 1
i 1 2
The result will be:
cd
abef
ef
You will be provided with main.cpp and function.h, and asked to implement function.cpp.
Input
The first line is an integer N indicating the number of input strings.
The following N lines each contains one input string.
Starting from the N+2th line will be a sequence of commands.
Output
Output the final result of the input strings.
Sample Input Download
Sample Output Download
Partial Judge Code
11417.cppPartial Judge Header
11417.hTags
Discuss
Description
Given two matrix A and B, compute the sum of all elements in matrix A*B.
We will give you 2 instance of Matrix, you should use the provided functions to complete the task.
Followng are some explanations about the functions:
int *get_row(int row): this function will return aint*pointer that points to the elements in the row-th row of the matrix.int *get_column(int col): this function will return aint*pointer that points to the elements in the col-th column of the matrix.int get_size(): this function will return aintrepresenting the size of the matrix (the matrix is of size*size).void remove(int *array): you should call this function to free the array returned by the previousget_row()orget_column(), otherwise you won't pass the memory check. (If you can't pass our memory check, there might be some error message in the end of your output, this will cause a Wrong Answer.)
Your are required to implement the int calculate(Matrix A, Matrix B). This function will return the sum of all elements in matrix A*B.
Remember to #include "function.h" in the beginning of your code!
Input
First line of input is an integer n, indicating that both of the matrix is of size n*n.
For the next n lines, each line i will consists of n numbers, representing the elements in the i-th row of the first matrix.
For the next n lines, each line j will consists of n numbers, representing the elements in the j-th row of the second matrix.
It is guaranteed that:
- Each element in the matrix won't exceed 20.
- 2 ≤ n ≤ 100
Output
If you passed our memory check, the output will contain an integer representing the sum of the elements in matrix A*B.
Otherwise, there might be some error code, which is something that you should try to get rid of.
Sample Input Download
Sample Output Download
Partial Judge Code
11897.cppPartial Judge Header
11897.hTags
Discuss
Description
If you are not familiar with partial judge , please check this handout
Implement a Vector class that support n-dimensional vector add, subtract and dot product.
Your task is to complete
- const int size() const;
- Vector operator+(const Vector& a);
- Vector operator-(const Vector& a);
- const int operator[](int index) const;
- int operator*(const Vector& a);
inside the Vector class, and std::ostream& operator<<(std::ostream& os, const Vector& v);
Remember to #include "function.h"!
Input
First line of input is an integer m, where m is the number of testcases.There are m testcases following.
A testcases consists of three lines:
- In the first line of each testcase, there are a string OP and an integer n, where OP is the operation and n is the vector size.
- In the second line of each testcase, there are n integers, representing all the elements inside the first vector, A.
- In the third line of each testcase, there are n integers, representing all the elements inside the second vector, B.
It is guaranteed that:
- 1 ≤ m ≤ 100, 1 ≤ n ≤ 300
- For all the elements x in vector A and B, |x| ≤ 100
Output
For each testcase, according to its operation, output the result of A+B, A-B or A*B. There is a space after every number.