Untitled
unknown
c_cpp
2 years ago
1.4 kB
9
Indexable
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <math.h>
#include<set>
#include<map>
#include<sstream>
using namespace std;
int cnt = 0;
struct HocSinh {
string Ma;
string HoTen;
double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10;
double DiemTB;
friend istream& operator >> (istream& in, HocSinh &x) {
cnt++;
string res = to_string(cnt);
while (res.size() < 2) {
res = "0" + res;
}
x.Ma = "HS" + res;
getline(in, x.HoTen);
in >> x.d1 >> x.d2 >> x.d3 >> x.d4 >> x.d5 >> x.d6 >> x.d7 >> x.d8 >> x.d9 >> x.d10;
x.DiemTB = (2 * x.d1 + 2 * x.d2 + x.d3 + x.d4 + x.d5 + x.d6 + x.d7 + x.d8 + x.d9 + x.d10) / 12;
return in;
}
friend ostream& operator << (ostream& out, HocSinh x) {
out << x.Ma << " " << x.HoTen << " " << fixed << setprecision(1) << x.DiemTB << endl;
return out;
}
};
bool cmp(HocSinh a, HocSinh b) {
if (a.DiemTB != b.DiemTB) {
return a.DiemTB > b.DiemTB;
}
return a.Ma < b.Ma;
}
int main() {
int n;
cin >> n;
vector<HocSinh>v;
HocSinh x;
while (n--) {
cin.ignore();
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end(), cmp);
for (auto it : v) {
cout << it;
}
}Editor is loading...
Leave a Comment