# | Problem | Pass Rate (passed user / total user) |
---|---|---|
10998 | Stack |
|
13172 | Powers |
|
13472 | KYてぇてぇ — Birthday Present(class + reverse) |
|
14246 | I Like to be Rational |
|
14274 | Geometry |
|
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.hDiscuss
Description
This is a partial judge problem.
In this problem, you have to implement some power function in class special_power:
- special_power(int n) default constructor
- int fpow(int x) return xn % 880301
- int fpow(int x, int m) return xn % m
- int fpow() return 2n % 880301
- string fpow(string s) return sn
- string fpow(string s, int m) return sn % m
Note that n is a member in class special_power.
The definition of sn:
Repeat the elements of s n times, and connect them
For example:
- abcd4 = aaaabbbbccccdddd
- csst3 = cccssssssttt
The definition of sn % m:
Repeat the elements of s n times, and connect them.
If the length of sn is longer than m, ignore the remaining elements.
For example:
- abcd4 % 10 = aaaabbbbcc
- csst3 % 4 = cccs
Input
The input has only one line, contains three integer x, n, m and one string s.
For all testcase:
- 1 <= x, m <= 109
- 1 <= n <= 106
- 1 <= |s| <= 1000
- (1/6) 1 <= xn, 2n < m <= 880301, 1 <= |s| * n <= m
- (1/6) 1 <= xn, 2n < m <= 880301
- (1/6) 1 <= |s| * n <= m
Output
The output has five lines.
The 1st line, output the result of xn % 880301
The 2nd line, output the result of xn % m
The 3rd line, output the result of 2n % 880301
The 4th line, output the result of sn
The 5th line, output the result of sn % m
Sample Input Download
Sample Output Download
Partial Judge Code
13172.cppPartial Judge Header
13172.hTags
Discuss
Description
Kuo-chan is given a sequence A and a constant K as his birthday present from Yang-chan.
Kuo-chan is allowed to perfrom the following operation:
- push x — push x to the tail of A
- pop — remove the median value of A (the median value of A is A[ (|A|+1)/2 ], with index start at 1)
- programming tanoshi — for every element a in A, assign a % K to a
- reverse — reverse the whole A, the head becomes the tail and the tail becomes the head
Whenever performing pop operation, the length of A is guaranteed to be odd, hence A won't be empty.
For example, if A = [4, 3, 5], K = 2
push 11 ► A = [4, 3, 5, 11]
reverse ► A = [11, 5, 3, 4]
push 7 ► A = [11, 5, 3, 4, 7]
pop ► A = [11, 5, 4, 7]
programming tanoshi ► A = [1, 1, 0, 1]
Yang-chan is curious about what A is after Kuo-chan performs some operations to it.
Help him find it out!
(Remember to include function.h in your function.cpp file.)
Input
The first line contains three integers N K Q — the length of A, the constant Yang-chan gives Kuo-chan, the number of operations Kuo-chan performs.
The second line contains N integers a1, a2, ..., aN (1 <= ai <= N) — the elements of A.
Each of the next Q lines describes the operations. Each line is one of three types:
- push x (1 <= x <= 10000)
- pop
- programming tanoshi
- reverse
Different testcases have different constraints.
- N <= 103, Q <= 2N, K <= 4000, operations: {pop, push}
- N <= 103, Q <= 2N, K <= 4000, operations: {pop, push, programming tanoshi}
- N <= 105, Q <= 2N, K <= 4000, operations: {pop, push}
- N <= 105, Q <= 2N, K <= 4000, operations: {pop, push, programming tanoshi}
- N <= 105, Q <= 3N, K <= 4000, operations: {pop, push, programming tanoshi, reverse}
- N <= 105, Q <= 3N, K <= 4000, operations: {pop, push, programming tanoshi, reverse}
Output
You should print one line containing the elements of A after the operations. For 1 <= i <= |A|, the i-th number should be A[ i ].
Sample Input Download
Sample Output Download
Partial Judge Code
13472.cppPartial Judge Header
13472.hTags
Discuss
Description
Dogeon (鴿子) likes everything to be rational, just like himself. He thinks that it is irrational that floating-point numbers in C/C++ are not accurate. So he decides to implement a class Rational
to represent rational numbers. The class Rational
should have the following member functions:
Rational(int numerator, int denominator)
:
a constructor that takes two integersnumerator
anddenominator
to represent the rational number.Rational Add(Rational const& b) const
:
a member function that takes anotherRational
objectb
and returns a newRational
object that represents the sum of the two rational numbers.Rational Sub(Rational const& b) const
:
a member function that takes anotherRational
objectb
and returns a newRational
object that represents the subtraction of the two rational numbers.Rational Mul(Rational const& b) const
:
a member function that takes anotherRational
objectb
and returns a newRational
object that represents the multiplication of the two rational numbers.Rational Div(Rational const& b) const
:
a member function that takes anotherRational
objectb
and returns a newRational
object that represents the division of the two rational numbers.void print(std::ostream& os) const
:
a member function that prints the rational number in the simplest formnumerator/denominator
to the output streamos
. The simplest form means that the numerator and the denominator have no common divisor other than 1. Also, the denominator should be positive.
- This is a partial judge problem. All you have to do is to implement the functions mentioned above.
- This is a work of fiction. Any resemblance to actual persons, living or dead, or actual events is purely coincidental.
Input
The first line of the input contains an integer \(N\), the number of expressions to be evaluated.
The next \(N\) lines each contain the expression to be evaluated. Each expression contains two rational numbers \(\frac{n_{i,1}}{d_{i,1}}, \frac{n_{i,2}}{d_{i,2}}\) and an operator \(op_i\), separated by a space. The rational numbers are in the form numerator/denominator
and the operator is one of +
, -
, *
, /
.
\(N\)
\(n_{1,1}/d_{1,1} \quad op_1 \quad n_{1,2}/d_{1,2}\)
\(n_{2,1}/d_{2,1} \quad op_2 \quad n_{2,2}/d_{2,2}\)
\(\vdots\)
\(n_{N,1}/d_{N,1} \quad op_N \quad n_{N,2}/d_{N,2}\)
Constraints
- \(1 \leq N \leq 10^5\)
- \(-10^9 \leq n_{i,1}, d_{i,1}, n_{i,2}, d_{i,2} \leq 10^9\)
- It is guaranteed that the denominator of the rational numbers is not 0.
- It is guaranteed that if operator is
/
, the second rational number is not 0. - It is guaranteed that the simplest form of the result of each expression has a numerator and a denominator that are both within \([-10^9, 10^9]\).
Output
Each line of the output should contain the result of the corresponding expression in the simplest form \(n_{i,3}/d_{i,3}\).
$\frac{n_{i,3}}{d_{i,3}} = (\frac{n_{i,1}}{d_{i,1}} \, \mathrm{op_i} \, \frac{n_{i,2}}{d_{i,2}})$, $d_{i,3} > 0$ and $\mathrm{gcd}(n_{i,3}, d_{i,3}) = 1$.
\(n_{1,3}/d_{1,3}\)
\(n_{2,3}/d_{2,3}\)
\(\vdots\)
\(n_{N,3}/d_{N,3}\)
Sample Input Download
Sample Output Download
Partial Judge Code
14246.cppPartial Judge Header
14246.hTags
Discuss
Description
In this problem, you are asked to implement a class Vector
that represents a vector in 2D space. The class should support the following operations:
- Addition (
+
) - Dot product (
*
) - Cross product (
^
)
Using these operations, you should also be able to calculate the following:
- The area of the triangle formed by two vectors
- The projection of vector \(v_1\) onto vector \(v_2\)
Warning: You should use C++11 or later versions, or else you will get Compile Error! reason
Hint: Please use std::abs
or fabs
instead of abs to get the absolute value.
Input
The first line contains two integers \(x_1, y_1\), which represents the first vector \(v_1\).
The second line contains two integers \(x_2, y_2\), which represents the second vector \(v_2\).
\(x_1 \quad y_1\)
\(x_2 \quad y_2\)
Constraints
- \(1 \le x_1,y_1,x_2,y_2 \le 1000\)
Output
As main function in "14274.cpp"