Compile-Time Timer Reload

#include <iostream>
using namespace std;

// Define constexpr computeReload here
constexpr auto clockHz = 1'000'000;
constexpr int computeReload(int _clockHz, int _intervalMs){
    return (_clockHz * _intervalMs + 500) / 1000;
};

// Define constexpr RELOAD_TABLE here
constexpr int RELOAD_TABLE[] = {
    computeReload(clockHz, 1),
    computeReload(clockHz, 10),
    computeReload(clockHz, 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