#include <iostream>
#include <cstdint>
using namespace std;

// Declare enum class AdcConfig : uint8_t
enum class AdcConfig : uint8_t{
    ChannelEnable = 1,
    InterruptEnable = 2,
    DMAEnable = 4
};

// Implement void printConfig(uint8_t cfg)
void printConfig(uint8_t cfg){
    int check = 0;
    if(cfg & static_cast<uint8_t>(AdcConfig::ChannelEnable)){
        cout << "ChannelEnable";
        check = 1;
    }
    if(cfg & static_cast<uint8_t>(AdcConfig::InterruptEnable)){
        if(check) cout << " ";
        cout << "InterruptEnable";
        check = 1;
    }
    if(cfg & static_cast<uint8_t>(AdcConfig::DMAEnable)){
        if(check) cout << " ";
        cout << "DMAEnable";
        check  = 1;
    }
    if(!check){
        cout << "None";
    }
}
int main() {
    int ch, intr, dma;
    cin >> ch >> intr >> dma;

    uint8_t cfg = 0;
    if (ch)   cfg |= static_cast<uint8_t>(AdcConfig::ChannelEnable);
    if (intr) cfg |= static_cast<uint8_t>(AdcConfig::InterruptEnable);
    if (dma)  cfg |= static_cast<uint8_t>(AdcConfig::DMAEnable);

    printConfig(cfg);
    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

1 0 1

Expected Output

ChannelEnable DMAEnable