#include <iostream>
using namespace std;

// Define LED class here
// <write your code>
class LED{
    int pin;
    int state;
    public:
    LED(int p) : pin(p),state(0){}
    void on(){
        state=1;
    }
    void off(){
        state=0;
    }
    void toggle(){
        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