Files
contests/2022/city/11/energie/energie.cpp

77 lines
1.9 KiB
C++

#include <bits/stdc++.h>
using namespace std;
// ifstream in("test.in");
// ofstream out("test.out");
struct Consumer {
int consumed;
string name;
bool operator<(const Consumer& other) {
// First compare x, then y
return consumed < other.consumed;
}
};
int main(int argc, char *argv[]) {
string inName = "test.in";
string outName = "test.out";
if (argc > 1) {
inName = argv[1];
cout << "Using \"" << inName << "\" for test name" << endl;
} else {
cout << "Warning: no in name provided, defaulting to test.in" << endl;
}
if (argc > 2) {
outName = argv[2];
cout << "Using \"" << outName << "\" for out name" << endl;
} else {
cout << "Warning: no out name proviced, defaulting to test.out" << endl;
}
ifstream in(inName);
ofstream out(outName);
int n;
in >> n;
string tmpLName;
string tmpFName;
int tmpConsumption = 0;
int totalConsumption = 0;
// Consumer* consumers[n];
vector<Consumer> consumers;
consumers.reserve(n);
for (int i = 0; i < n; i++) {
in >> tmpLName;
in >> tmpFName;
in >> tmpConsumption;
totalConsumption += tmpConsumption;
Consumer* cons = new Consumer();
consumers.push_back(*cons);
(consumers[i].consumed) = tmpConsumption;
(consumers[i].name) = tmpLName + " " + tmpFName;
}
sort(consumers.begin(), consumers.end());
out << fixed << setprecision(2) << setw(10) << ((float)(totalConsumption) / (float)n) << endl;
for (auto it = consumers.begin(); it != consumers.end(); it++) {
#define consumer (*it)
out << consumer.name << " " << consumer.consumed << endl;
}
// out << biggestConsumer << " " << maxConsumption << endl;
// out << smallestConsumer << " " << minConsumption << endl;
return 0;
}