Compile-Time Timer Reload

#include <iostream>
using namespace std;

// Define constexpr computeReload here
constexpr unsigned int computeReload(unsigned int clockHz,unsigned int intervalMs){
    return (clockHz * intervalMs + 500)/1000;
}

// Define constexpr RELOAD_TABLE here
constexpr unsigned int  RELOAD_TABLE[] = {computeReload(1'000'000,1),computeReload(1'000'000,10),
computeReload(1'000'000,100)
};

int main() {
    int idx;
    cin >> idx;

    // Print RELOAD_TABLE[idx]
    cout<<RELOAD_TABLE[idx];

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

0

Expected Output

1000