Construct Sensor Packet Placement

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

// Write your struct and placement new logic here
struct SensorPacket{
    int id;
    int value;
};


int main() {
    alignas(SensorPacket) unsigned char pool[3][sizeof(SensorPacket)];
    int index, id, value;
    cin >> index >> id >> value;

    SensorPacket* pkt=new(pool[index]) SensorPacket{id,value};

    cout<<pkt->id<<" "<<pkt->value;

    pkt->~SensorPacket();
    // Write your pool construction code here

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

1 50 900

Expected Output

50 900