#include <iostream>
#include <string>

class SPIBus;

class DisplayDriver {
public:

    void fastWrite(SPIBus& bus, int v1, int v2);
};

class SPIBus {
private:
    int buffer[2];
    friend class DisplayDriver;
public:
    SPIBus() {
        buffer[0] = 0;
        buffer[1] = 0;
    }

    void dump() {
        std::cout << "Buffer: [ " << buffer[0] << " " << buffer[1] << " ]" << std::endl;
    }
};

void DisplayDriver::fastWrite(SPIBus& spi, int v1, int v2){
    spi.buffer[0] = v1;
    spi.buffer[1] = v2; 
}


int main() {
    SPIBus bus;
    DisplayDriver driver;
    int N;
    if (!(std::cin >> N)) return 0;

    for (int i = 0; i < N; ++i) {
        std::string cmd;
        std::cin >> cmd;

        if (cmd == "WRITE") {
            int v1, v2;
            std::cin >> v1 >> v2;
            driver.fastWrite(bus, v1, v2);
        } else if (cmd == "SHOW") {
            bus.dump();
        }
    }
    return 0;
}

Solving Approach

 

 

 


 

Upvote
Downvote
Loading...

Input

3 SHOW WRITE 55 99 SHOW

Expected Output

Buffer: [ 0 0 ] Buffer: [ 55 99 ]