# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14283 | Fraction Calculator (Lite) |
|
14284 | More Polymorphic Codec Classes |
|
14285 | Gaming Battle (Part I: Tic-tac-toe) |
|
14322 | Gaming Battle (Part II: Tetris) |
|
Description
Your task is to create a basic fraction calculator that can handle the multiplication of fractions.
In the provided code, you are advised to use a structure called "FractionList", which functions similarly to a linked list. When performing a multiplication, add the new fraction to the end of the list. Then, multiply all the fractions in the list and output the answer.
This is a partial judge problem. You need to implement 3 class methods. Please review the provided code and refer to the sections labeled "TODO" in the function.h file for further details.
Important: Please select C++17 to submit your solution.
Input
The first line of the input contains an integer N, representing the number of test cases. (1 ≤ N ≤ 5 × 104)
Each of the following N lines represents a test case.
Each test case contains a sequence of fractions and operations formatted as follows:
<fraction_1> * <fraction_2> * ... * <fraction_n> =
(1 < n ≤ 15)
Each fraction is written in the format <numerator>/<denominator>
, where both numerator and denominator, as well as all numbers involved in calculations, fit within the range of a long long data type.
Output
For each test case, you should output the original problem and the result, with resulting fraction presented as a simplified fraction reduced to its lowest terms. The format for each test case should be as follows:
<fraction_1> * <fraction_2> * ... * <fraction_n> = <result_fraction>
Additional constraint:
- If the result is an integer (e.g., 3), output should be formatted as:
3/1
. - The result will not be 0.
- It's guaranteed that all the fractions in the given problem are irreducible.
Sample Input Download
Sample Output Download
Partial Judge Code
14283.cppPartial Judge Header
14283.hTags
Discuss
Description
This is a partial judge problem.
You're asked to implement encode function in several class that inherit the base class "Codec".
class Codec { public: Codec(std::string s): code_str{s} {} virtual ~Codec() {} virtual void encode() = 0; void show(std::ostream& os) const { os << code_str; } protected: std::string code_str; };
There are three types of Codec.
The first one is the AB Codec, it should turn all the 'A' to 'B', and all the 'B' to 'A'. ('A', 'B' are upper case english character)
The second one is the Comma Codec, it should add a comma ',' every 5 characters. For example, the string "HELLOWORLD" will turn into "HELLO,WORLD," after encoding.
The third one is the Numeric RLE Codec which enhances traditional encoding methods. This codec involves a multi-step transformation process:
- Alphabet to Numeric: Each letter from 'A' to 'Z' is converted to a corresponding numeric code from '00' to '25'.
- Numeric to Alphabetic: Each digit from '0' to '9' is then transformed into a corresponding lower case letter from 'a' to 'j'.
- Run-Length Encoding: Finally, we apply run-length encoding to the resulting string.
To encode the string "AAAAB" using the Number RLE Codec, follow these steps:
- Convert 'A' to '00' and 'B' to '01', turning "AAAAB" into "0000000001".
- Replace '0' with 'a' and '1' with 'b', resulting in "aaaaaaaab".
- Apply run-length encoding to get "9ab".
What is run-length encoding? : 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. 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’.
TODOs: In ‘function.cpp’, please implement the function encode() in class "ABCodec", "CommaCodec", and "NumRLECodec".
For more information, you should refer to the main.cpp and function.h.
Notes: When you submit, you need to implement all three encode function (you can left it empty inside) or you will get a compile error.
Input
The first line contains a string, which can be ‘AB’, ‘Comma’ or ‘NumRLE’.
The second line contains a string with only uppercase letters, representing the string to be encoded.
Constraints:
Testcases 1~4: The first line would be ‘AB’.
Testcases 5~8: The first line would be ‘Comma’.
Testcases 9~10: The first line would be ‘NumRLE’.
Output
Output the encoded string.
Please refer to the sample output for details.
Sample Input Download
Sample Output Download
Partial Judge Code
14284.cppPartial Judge Header
14284.hTags
Discuss
Description
Your task is to develop a program that supports the Tic-tac-toe game.
- Tic-tac-toe rules
- The goal is to be the first to get three of your marks in a row (horizontally, vertically, or diagonally).
- Players take turns placing their symbol (either X or O) in an empty square on a 3x3 grid.
- The first player to align three of their symbols in a row on the grid wins the game.
- If all nine squares are filled and no player has three marks in a row, the game is a draw.
This is a partial judge problem. Please review the provided code and refer to the sections labeled "TODO" in the function.h file for further details, and using C++17 to submit your solution.
Input
The first line of the input contains an integer N, representing the number of test cases. (1 ≤ N ≤ 5 × 104)
Each of the following N lines represents a test case. Each line records a game session, detailing every move made by the players. The game may conclude early if one player wins. The game records are formatted as follows (- -
represents the end of each test case):
<player1_symbol> <Move> <player2_symbol> <Move> ... <player1or2_symbol> <Move> - -
We guarantee that players will not play out of turn or make illegal moves, such as placing pieces on already occupied spaces.
The player's symbol will be either "O" or "X". The move format for Tic-tac-toe is x/y
where "x" represents the row and "y" represents the column, indicating the placement of a piece on the board at position board[x][y]
.
Output
Refer to the sample output provided.
If a game concludes without a winner after all moves in each testcase, output "Tie". Otherwise, tell the winner of the game. Additionally, display the status of the board at the end of the game. Please ensure to leave an empty line in the output at the end of each test case.
Sample Input Download
Sample Output Download
Partial Judge Code
14285.cppPartial Judge Header
14285.hTags
Discuss
Description
Notice. Some of the TODOs are identical to those in Part 1: Tic-tac-toe (these are marked with TODO_xx in function.h). If you have already completed Part 1: Tic-tac-toe, you can copy the solution from Part 1 and further implement the remaining 3 TODOs in this problem (Board::Board(const Board& b)
, Board& Board::operator=(const Board &b)
and TetrisBoard& TetrisBoard::operator+=(const Move& m)
).
Your task is to adapt the framework that supports board games to also support another classic game, Tetris (俄羅斯方塊).
To simplify the problem, we will modify the rules of Tetris. In Tetris, players drop differently shaped blocks that descend onto the playing field, and the game ends when the blocks exceed the top of the playing field. (Tips for those familiar with Tetris: In the original version of game, completed lines disappear; however, in this version, they won't disappear)
We are interested in determining how many blocks can be dropped given a sequence of blocks with specific rotations and dropping positions.
There are 7 types of blocks, each represented by '.' and an arbitrary lowercase letter.
The following GIF illustrates the 1st sample I/O.
This is a partial judge problem. Please review the provided code and refer to the sections labeled "TODO" in the function.h file for further details, and using C++17 to submit your solution.
Input
The first line of the input contains an integer N, representing the number of test cases (1 ≤ N ≤ 5,000).
For each of the N test cases, the first line contains two integers, x and y (4 ≤ x, y ≤ 20), representing the height and width of the playing field, respectively. This is followed by a sequence of blocks to be dropped.
Each block in the sequence is preceded by three integers: bx, by, and c, where bx and by denote the height and width of the block, and c indicates the leftmost column position for dropping the block. Each block is represented by '.' and an arbitrary lowercase letter (stored in a vector<string>; please review the provided code). The sequence or test case ends when bx = by = c = 0.
We guarantee that the position for dropping the block will not exceed the width of the playing field.
Test Case Constraints
- Testcases 1, 2: For these test cases, only the following block will be given as input:
Since there is only one possible block, we provide a trivial implementation ofTetrisBoard::operator+=
for your reference. You can simply paste the code to pass the two test cases.
int rows = getRows(), dc = m.getDropColumn(), st_row = rows - 4;
for (int i = 0; i < rows; ++i) {
if ((*this)[i][dc] != '.') {
st_row = i-4;
break;
}
}
if (st_row < 0) isGameEnd = true;
else {
for (int i = 0; i < 4; ++i) {
(*this)[st_row+i][dc] = m.getBlock()[i][0];
}
}
return *this;
}
- Testcases 3, 4: For these test cases, only the following blocks will be given as input:
- Testcases 5, 6: All seven blocks can be dropped in rotations of 0, 90, 180, and 270 degrees.
Output
Output the playing field as shown in the sample output provided.