#include <iostream>
using namespace std;

// Define LED class here
// <write your code>
class LED {
private:
    int pin;    // GPIO pin number
    int state;  // 0 = OFF, 1 = ON

public:
    // Constructor initializes pin and sets LED to OFF
    LED(int p) : pin(p), state(0) {}

    void on() {
        state = 1;
    }

    void off() {
        state = 0;
    }

    void toggle() {
        state = state ^ 1;
    }

    int status() {
        return state;
    }
};
int main() {
    int pin, initialState, toggleCount;
    cin >> pin >> initialState >> toggleCount;

    LED led(pin);

    if (initialState == 1)
        led.on();
    else
        led.off();

    for (int i = 0; i < toggleCount; i++) {
        led.toggle();
    }

    cout << led.status();
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

5 1 3

Expected Output

0