2998 - I2P(II)2024_Yang_mid2_practice Scoreboard

Time

2024/04/26 15:20:00 2024/05/10 13:20:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

12257 - Only children make choice!   

Description

"Cat or Dog? that's a good question. " Shakespeare never said, 2019.

In this questions there are three types of animals class have to be implemented. (Cat , Dog and Caog)
Coag is a kind of special animal mixed in Cat and Dog.

Dog can only throwball
Cat can only play with carton.
Caog do those things both.

when Dog Caog playing throwball output "it looks happy!\n"

when Cat  / Caog playing with carton output "it looks so happy!\n"

and also there's a zoo can count how many animals are in the zoo.

In this questions you have to implement 3 class (cat , dog and caog) based on the sample code.

Input

All input data would be finish in given main functions.

First number N would be N animals ( N < 10)

the following Ai numbers would types of animals.

And the T would be T instructions ( T < 30) 

the following Ti would be index and instructions

 

Output

 

When Animals born Zoo will auto output which kind of animal is born and how many animals in the zoo.

When Animals dead Zoo will auto output which kind of animal isdeadand how many animals in the zoo.

when Dog Caog playing throwball output "it looks happy!\n"

when Cat  Caog playing with carton output "it looks so happy!\n"

when Barking:

Cat would "meow!\n"

Dog would "woof!\n"

Caog would "woof!woof!meow!\n"

Sample Input  Download

Sample Output  Download

Partial Judge Code

12257.cpp

Partial Judge Header

12257.h

Tags




Discuss




13522 - Infinitely Big Integer: Darray Implementation   

Description

The problem "Infinitely Big Integer" is splitted into two subproblems:

  1. Darray Implementation (3/10)
  2. Big Integer Implementation (7/10)

You should solve this subproblem first.

Based on the definition of Dynamic Array in Problem 13520 (nthu.edu.tw), you need to implement a dynamic array with the following functions:

  1. int& operator[](int): access data like using array. Users and main.cpp should/will not access the index which is greater or equal to size.
  2. void pushback(int x): append the element x
  3. void popback(void): pop the last element. Don't do anything if the array is empty.
  4. void clear(void): clear the array (set size to 0) so that the next pushbacks will place elements in data[0],data[1] and so on.
  5. int length(void): return the current size.
  6. void resize(void): double the capacity and copy the data.
  7. ~Darray(): destructor

Note that main.cpp acts like a functional tester for your Darray. There's no need to understand it. You should test your Darray by yourself. Furthermore, a new function void popback(void) is introduced in this problem.

// function.h
class Darray {
    public:
        Darray() {
            capacity = 100;
            size = 0;
            data = new int[capacity];
        };
        ~Darray();
        int& operator[](int);
        void pushback(int x);
        void popback(void);
        void clear(void);
        int length(void);
    private:
        void resize(void); // double the capacity
        int *data;
        int capacity;
        int size;
};
// usage
Darray arr;
for (int i = 0; i < 5; i++) arr.pushback(i*i);
arr[2] += 100 + arr[3];

for (int i = 0; i < arr.length(); i++)
    cout << arr[2] << ' ';             // 
Print: 0 1 113 9 16
cout << endl << arr.length() << endl;  // Print: 5
arr.clear();

cout << arr.length() << endl;          // Print: 0
arr.pushback(9487); 
arr.pushback(9487);
arr.popback();

cout << arr.length() << ' ' << arr[0] << endl;  // Print: 1 9487

 

std::vector is prohibited (both subproblems 1 and 2) and will result in 0 score if you use it. 

Input

This is handled by the main function.

1/3 of the test cases will not test popback(). If you have problems with it, try writing an empty popback function so that it can be compiled successfully.

// in function.cpp
void popback() {
}

Output

This is handled by the main function.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13522.cpp

Partial Judge Header

13522.h

Tags




Discuss




13523 - Infinitely Big Integer: Big Integer Implementation   

Description

The problem "Infinitely Big Integer" is splitted into two subproblems:

  1. Darray Implementation (3/10)
  2. Big Integer Implementation (7/10)

You should solve the former, Darray Implementation, first.

You may have practiced the problem Big Integer before. Instead of using traditional int, we store the integer in a char array. However, it still has size limitation because we declare a static array for the class. In this problem, we'll use the Darray in problem 13522 - Infinitely Big Integer: Darray Implementation as the data array in class INT to handle arbitary large numbers as long as the memory of the computer is enough.

The following is the structure of INT.

class INT {
    public:
        void operator+=(INT&);
        friend std::istream &operator>>(std::istream &, INT &);
        friend std::ostream &operator<<(std::ostream &, INT &);
    private:
        Darray data;
};

For simplicity, you only need to implement three functions, <<, >> and +=. The streaming operators are used for cin and cout. The operator += does the same as the traditional operator +=. For instance, A += B, A will be the value of A+B and B remains the same. Note that all the parameters are passed by reference, which is different from the previous problem.

Your function.cpp should contain the implementation of both Darray and INT. If you passed the subproblem 1 first, just copy and paste the Darray. For example:

// function.cpp
#include "function.h"
// Darray
void Darray::pushback(int x) { ... }
...

// INT
void INT::operator+= (INT &b) { ... }
...

It is okay if you have problems with the popback function in subproblem 1 as long as the Darray has basic functionality to pass the test cases, because Darray in INT is fully controlled by you.

The following is an alternative main.cpp to test your code:

#include <iostream>
#include "function.h"
using namespace std;
int main() {
    INT a, b;
    cin >> a;
    cin >> b;
    a += b;
    cout << "a + b = " << a << endl;
    return 0;
}

 

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

13523.cpp

Partial Judge Header

13523.h

Tags




Discuss




13862 - Pineapple senpai’s family   

Description

Katex

Pineapple Senpai is introducing his family to you.

Each member of his family has some strong relatives such as ParentA, ParentB, Mate, and Child.

And there would be a narrator in the family, who is responsible to introduce the family to you.

Initially, the narrator is Pineapple Senpai himself, and the narrator would introduce his relative's attributes such as gender, age, name, and personality.

Each relative is selected by a strong-relative-chain. For example, if the strong-relative-chain is "ParentA Child", it means that the relative is the narrator's ParentA's Child(which is the narrator itself).

So there are three types of queries you need to proceed

  • 1 strong-relative-chain
  • this type of query asks you to change the narrator to the current narrator's relative, which is selected by the strong-relative-chain.
  • 2 strong-relative-chain attribute-modification
  • this type of query asks you to change the attribute of the current narrator's relative, which is selected by the strong-relative-chain. the attribute-modification's would specify the name of the attribute, and the value to be changed. There are four types of attributes: "Gender: ENUM, Age: INT, Name: STRING, Personality: STRING".
  • 3
  • this type of query asks you to print the info of the current narrator, you should call the built-in function directly.

Note that the first time every relative is introduced to you, there may be some information that is not directly revealed by the narrator but you should notice.

When a Child is first introduced to you, at least one of its parent is introduced early, which should be the Child's ParentA.

A Child's ParentA and ParentB should always be Mate to each other.

If B is A's Mate, A's Child would be B's Child, too.

Each time a perstonality is described, you should concatenate the new described personality behind the original personalities spacing by a single space character.

    Constraints

  • \(1 \leq Q \leq 1000\)
  • \(1 \leq len(strong-relative-chain) \leq 1000\)
  • \(1 \leq len(attribute-chain) \leq 200\)

This is a Partial judge Problem.

All you need to do is to implement the getRelative and describe function.

For the getRelative function, you should return the pointer to the relative that is selected by the strong-relative-chain

For the describe function, you should modify the corresponding attribute of the relative selected by the strong-relative-chain

Note that you should compile the solution with C++17.

Input

Katex First line is \(Q\), so there are \(Q\) queries. Next \(Q\) lines, each line contains a query.

Output

Katex Output the info of the narrator for each type 3 query.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13862.cpp

Partial Judge Header

13862.h

Tags

Pineapple Senpai



Discuss




14280 - Fraction Comparator   

Description

Your task is to create a fraction comparator that can handle the comparison of two fraction formulas that contain only addition.

In the provided code, you are advised to use a structure called "FractionList", which functions similarly to a linked list. When performing an addition, add the new fraction to the end of the list. Then, sums up all the fractions in each list and compares the result in the end.

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.

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_n> <operator> <fraction_1> + ... + <fraction_m> ->  (5 ≤ n, m < 10)

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. The operators for each test case can be either "<", ">", "<=", or ">=".

 

Output

For each test case, output one line: If the given expression is true, output "True". Otherwise, output "False".

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

14280.cpp

Partial Judge Header

14280.h

Tags




Discuss




14281 - Polymorphic Run-Length Encoding Class   

Description

The task is to define the class ‘RleCodec’ for 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’.


Abstract base class ‘Codec

We first design the abstract base class ‘Codec’ as an interface, which contains two pure virtual functions encode() and decode()

class Codec {
public:
    Codec(std::string s): encoded{false}, code_str{s} { }
    virtual ~Codec() { } // virtual destructor; do nothing
    virtual void encode() = 0;
    virtual void decode() = 0;
    void show(std::ostream& os) const {
        os << code_str;
    }
    bool is_encoded() const { return encoded; }
protected:
    bool encoded;
    std::string code_str;
};

TODOs: In ‘function.cpp’, please

  1. define two concrete derived classes from the abstract base class ‘Codec’ by overriding the two pure virtual functions:
  • class DummyCodec: simply updating the coding status in encode() and decode() accordingly, and doing nothing else;
  • class RleCodec: for the run-length encoding explained above;
  1. implement the function getCodec(), which returns the address of a Codec object according to the parameter type, where the type of the Codec can be "Dummy" or "RLE".
Codec* getCodec(const std::string& type, const std::string& is);

For more information, you should refer to the main.cpp and function.h.


Note
It is highly recommended to practice std::stringstream in this problem. Here is a simple code that shows you how to use stringstream:

#include <iostream>
#include <sstream> // header file for stringstream
using namespace std;
int main(){
    string s;
    stringstream ss;
    getline(cin, s);
    ss << s;
    while(!ss.eof()){
        string t;
        getline(ss, t, ' ');
        cout << t << "\n";
    }
    return 0;
}
/*
- Sample Input
This is a sentence for testing this code.
- Sample Output
This
is
a
sentence
for
testing
this
code.
*/

For more information, please refer to this article.

Input

The input contains a single line that consists of several characters.

Output

There are four lines.

The first and second lines are dummy encoding and decoding.

The third and fourth lines are RLE encoding and decoding.

Each line is followed by a new line character.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14281.cpp

Partial Judge Header

14281.h

Tags




Discuss




14282 - After the Gomoku Battle   

Description

 

 

After playing Gomoku for a whole day, Doraemon and Capoo are looking to try new games.They are interested in exploring other classic board games, such as Tic-tac-toe and Connect4, which share the "n-in-a-row" style with Gomoku. Your mission is to develop a program that supports the games of Tic-tac-toe and Connect4 for them to play.

  • Tic-tac-toe (https://en.wikipedia.org/wiki/Tic-tac-toe)
    • 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.
    • In this problem, the first player uses "O" and places their symbol first, followed by the second player who uses "X".
  • Connect4 (https://en.wikipedia.org/wiki/Connect_Four)
    • The goal is to be the first to form a horizontal, vertical, or diagonal line of four of one's own discs.
    • Players alternate turns dropping colored discs from the top into a 7-column, 6-row vertically suspended grid, the pieces fall straight down, occupying the lowest available space within the column.
    • The first player to get four of their discs in a row (horizontally, vertically, or diagonally) wins the game.
    • If the board is filled completely without any player forming a line of four, the game ends in a draw.
    • In this problem, the first player uses "W" discs and goes first, followed by the second player who uses "B" discs.

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 ≤ 100)

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:

<TicTacToe/ConnectFour> <Player1_Name>:<Move> <Player2_Name>:<Move> <Player1_Name>:<Move> ...

We guarantee that players will not play out of turn or make illegal moves, such as placing pieces on already occupied spaces.

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]; The move format for Connect4 is cx where "x" represents the column in which the disk is dropped.

 

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

14282.cpp

Partial Judge Header

14282.h

Tags




Discuss