C/C++

Задача на языке программирования C#

Массив записей содержит фамилии участников соревнования по прыжкам в длину и результаты трех попыток. Расположите записи в порядке занятых спортсменами мест. Воспользуйтесь поразрядной сортировкой.
#include <algorithm>
#include <iostream>
#include <array>
#include <string>
#include <set>
#include <iomanip>
using namespace std;
class Jumper {
public:
Jumper(string name) : name(name) {
box.fill(-1);
}
void add(const double value) {
for (auto i = 0U; i < box.size(); ++i) {
if (box[i] < 0) {
box[i] = value;
break;
}
}
}
double max()const {
return *max_element(box.begin(), box.end());
}
string person()const {
return name;
}
private:
string name;
array<double, 3U> box;
friend bool operator>(const Jumper& a, const Jumper& b) {
return a.max() > b.max();
}
friend ostream& operator<<(ostream& out, const Jumper& x) {
out << x.name;
for (auto n : x.box) cout << ' ' << n;
return out;
}
};
class Jumping {
public:
void record(const Jumper& x) {
list.insert(x);
}
void show()const {
cout << fixed << setprecision(2);
auto n = 0U;
for (const auto& item : list) {
cout << setw(3) << ++n << ". " << item << '\n';
}
}
private:
set<Jumper, greater<>> list;
};
void flush() {
cin.ignore(cin.rdbuf()->in_avail());
}
double real(const char* msg) {
cout << msg;
double value;
cin >> value;
flush();
return value;
}
Jumper results() {
cout << "Фамилия и имя участника: ";
string name;
getline(cin, name);
Jumper x(name);
x.add(real("Первая попытка: "));
x.add(real("Вторая попытка: "));
x.add(real("Третья попытка: "));
return x;
}
int main() {
system("chcp 1251 > nul");
cout << "Введите количество участников: ";
size_t n;
cin >> n;
flush();
Jumping jr;
for (auto i = 0U; i < n; ++i) jr.record(results());
system("cls");
jr.show();
system("pause > nul");
}
KH
Kakageldi Halysow
50 968
Лучший ответ