| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11014 | Encoding and decoding |
|
| 11437 | string exam |
|
| 11453 | Online course (bonus) |
|
| 11467 | 3DShape |
|
Description
The task is to define the class ‘RleCodec’ for run-length encoding.
About implementing the virtual function:
We have the base class ‘Codec’ as an interface. The member functions in ‘Codec’ are pure virtual functions. Therefore we need to implement those virtual functions in the derived class ‘RleCodec’. The functions ‘decode’, ‘show’, ‘is_encoded’ are already done. The only function you need to complete is ‘RleCodec::encode’ in ‘function.cpp’.
In ‘main.cpp’, we see two functions having an argument of type ‘Codec&’:
std::ostream& operator<<(std::ostream& os, Codec& data);
void encode_decode(Codec& data);
Since ‘RleCodec’ is a derived class of ‘Codec’, we may pass an object of ‘RleCodec’ to the above two functions by reference as if it is an object of ‘Codec’. Calling ‘data.show(os);’ will invoke the virtual function of the corresponding derived class.
About run-length encoding:
The rule of run-length encoding is simple: Count the number of consecutive repeated characters in a string, and replace the repeated characters by the count and a single instance of the character. For example, if the input string is ‘AAADDDDDDDBBGGGGGCEEEE’, its run-length encoding will be ‘3A7DBB5GC4E’, because there are three A’s, seven D’s, … etc. Note that we do not need to encode runs of length one or two, since ‘2B’ and ‘1C’ are not shorter than ‘BB’ and ‘C’.
In ‘function.h’, we add the class ‘DummyCodec’ as a sample of implementing a derived class of the base class ‘Codec’. You do not need to change anything in ‘function.h’. The only function you need to write for this problem is the function ‘RleCodec::encode’ in ‘function.cpp’.
Hint: std::stringstream could be useful in solving this problem. Please refer to ‘RleCodec::decode’ for how to use std::stringstream.
You only need to submit ‘function.cpp’. OJ will compile it with ‘main.cpp’ and ‘function.h’.
We have already provided partial function.cpp belowed.
Note that if you can't use "auto".
For codeblock, go to the codeblock menu Settings --> Compiler ... --> Compiler flags and check Have g++ follow the C++11 ISO C++ language standard [-std=c++11]
For command line compiler, use g++ myprog.cpp -std=c++11 -o myprog
main.cpp
function.h
function.cpp
Input
A line contains of several characters .
Output
There are four lines.
The first and second lines are dummy encoding and decoding. You don't need to implement it.
The third and forth lines are RLE encoding and decoding.
Each line is followed by a new line character.
Sample Input Download
Sample Output Download
Partial Judge Code
11014.cppPartial Judge Header
11014.hTags
Discuss
Description
Write a program that will reverse the order of words in each sequence of sentences while preserve the order of letters.
Input
The input file will consist of several lines of several words. Words are contiguous stretches of printable characters delimited by a white space.
Output
The output will consist of the same lines and words as the input file. However, the order of words will be reversed.
Sample Input Download
Sample Output Download
Partial Judge Code
11437.cppPartial Judge Header
11437.hTags
Discuss
Description
In this problem, students can use accounts to take online courses.
The program architecture is explained as follows.
A. Definition of class Student
- An abstract base class that declares pure virtual learn() method
- Has a string (note) used to record what the student learns
- Derived classes
- InterestedStudent
- Just note the latest thing
- StrivingStudent
- Note everything learned
- InterestedStudent
B. Definition of class Account
- A node of doubly linked list
C. Definition of class OnlineCourse
- An abstract base class that declares pure virtual material() method
- Operator+= means login
- A student can use an account to login an online course.
- Operator-= means logout
- If a student has been taking an online course, he/she can logouts the online course.
- Derived classes
- Math
- The input will be a pre-order expression with +, -, *, /
- material() method has to return the answer of the expression
- English
- The input will be a string
- material() method has to separate the characters of the input string by new lines if a next character is uppercase
- Math
You are asked to implement
- void InterestedStudent::learn(const string &str)
- The Student learns the material by saving the input str to the note.
-
void StrivingStudent::learn(const string &str)
- Note: if he/she learns something, you need to attach a new line and then the new material to the “note”.
-
void OnlineCourse::operator+=(Student *s)
-
create an Account for the Student and insert the Account to the doubly linked list.
-
Note:
-
A student cannot login a same course for more than one time.
-
But a student can logout a course, and then login again.
-
-
-
void OnlineCourse::operator-=(Student *s)
-
remove the Account for the Student from the doubly linked list and then delete the Account.
-
-
string Math::material(istream &input)
-
string English::material(istream &input)
-
Note: you don’t need to insert a new line before the first character, even if it’s uppercase.
-
Input
First line contains an integer n and n types from {m, e}
- Integer n means n online courses
- type m means Math
- type e means English
Second line contains an integer m and m types from {i, s}
- integer m means m students
- type i means InterestedStudent
- type s means StrivingStudent
and then, there are 4 kinds of commands
- i n m:
m-th student logins n-th course
- o n m:
m-th student logouts n-th course
- u n:
there are new input for n-th course
- s m:
show the note of m-th student
Output
the output depends on the input commands.
Sample Input Download
Sample Output Download
Partial Judge Code
11453.cppPartial Judge Header
11453.hTags
Discuss
Description
Warning: You are not allowed to use malloc and free
Giving a bass-class Shape3D and 2 derived class : Sphere, Cube
You need to calculate the volume of each shape.
PS:
V of Sphere: V = 4/3 π r3
note : Remember to do some basic check, if the input is illegal (e.g. length < 0, pi < 0 .....) then the volume should be 0.
You don't need to consider the scenario like Cube -2, volume would be 0 instead of -8.
Hint1: Be careful the type of volume is double. 4/3=1 (int), so it should be 4.0/3.0
Hint2: You only need to implement the constructors.
Input
There are only 2 shapes in this problem :
- Sphere, following by its radius and pi. (e.g. Sphere 30 3.14)
- Cube, following by its length. (e.g. Cube 2)
Output
Ouput the total volume of all the shapes.