added files
This commit is contained in:
parent
69bc9646e4
commit
e50051b8e6
5 changed files with 307 additions and 0 deletions
53
record.hpp
Normal file
53
record.hpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
class Record {
|
||||
public:
|
||||
std::array<int, 5> a;
|
||||
int x;
|
||||
|
||||
int evaluate() const
|
||||
{
|
||||
int out = 0;
|
||||
int x_n = 1;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
out += a[i] * x_n;
|
||||
x_n *= x;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool operator<(const Record& other) const
|
||||
{
|
||||
return evaluate() < other.evaluate();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Record& r)
|
||||
{
|
||||
os << r.a[0] << ' ' << r.a[1] << ' ' << r.a[2] << ' '
|
||||
<< r.a[3] << ' ' << r.a[4] << ' ' << r.x;
|
||||
return os;
|
||||
}
|
||||
|
||||
friend std::istream& operator>>(std::istream& is, Record& r)
|
||||
{
|
||||
is >> r.a[0] >> r.a[1] >> r.a[2] >> r.a[3] >> r.a[4] >> r.x;
|
||||
return is;
|
||||
}
|
||||
|
||||
static Record random()
|
||||
{
|
||||
static std::random_device rd;
|
||||
static std::mt19937 gen(rd());
|
||||
static std::uniform_int_distribution<int> dist;
|
||||
|
||||
Record r;
|
||||
for (int& val : r.a) {
|
||||
val = dist(gen);
|
||||
}
|
||||
r.x = dist(gen);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue