#include <iostream>
#include <cstdint>

using namespace std;

class Frame {
private:
    uint8_t buffer[16]; // Fixed internal buffer
    int currentSize;    // Tracks the current number of bytes stored

public:
    // Constructor initializes the frame as empty
    Frame() : currentSize(0) {}

    // Overload += to append a single byte
    void operator+=(uint8_t byte) {
        if (currentSize < 16) {
            buffer[currentSize] = byte;
            currentSize++;
        }
    }

    // Overload [] for read-only access by index
    uint8_t operator[](int index) const {
        // In a production environment, you might add bounds checking here
        return buffer[index];
    }

    // Method to retrieve the current frame size
    int getSize() const {
        return currentSize;
    }
};

int main() {
    int n;
    if (!(cin >> n)) return 0;

    Frame frame;

    // Read n integers and append them to the frame
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        // Cast the input int to uint8_t and append using +=
        frame += static_cast<uint8_t>(b);
    }

    // Print the frame contents using operator[] and getSize()
    for (int i = 0; i < frame.getSize(); i++) {
        cout << (int)frame[i]; // Cast to int for readable decimal output
        if (i + 1 < frame.getSize()) {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

4 10 20 30 40

Expected Output

10 20 30 40