#include "pch.h" #include #include #include #include #include #include using namespace std; struct salota{ string pav; double a = 0; double b = 0; double r = 0; double h2o = 0; int nr = 0; }; salota m[222]; int n = 0; void skaitymas(int &n, salota m[]); void rikiavimas(int n, salota m[]); void spausdinimas(int n, salota m[]); int main() { skaitymas(n, m); rikiavimas(n, m); spausdinimas(n, m); } void skaitymas(int &n, salota m[]) { char x[15]; ifstream d("duom.txt"); d >> n; d.ignore(); for (int i = 0; i < n; i++) { m[i].nr = i; d.get(x, 15); m[i].pav = x; d >> m[i].a >> m[i].b >> m[i].r; d.ignore(); m[i].h2o = 100-(m[i].a + m[i].b + m[i].r); } d.ignore(); d.close(); } void rikiavimas(int n, salota m[]) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ((m[i].b < m[j].b) || ((m[i].b == m[j].b) && (m[i].h2o > m[j].h2o))) { swap(m[i].b, m[j].b); swap(m[i].h2o, m[j].h2o); swap(m[i].pav, m[j].pav); swap(m[i].r, m[j].r); swap(m[i].a, m[j].a); } } } } void spausdinimas(int n, salota m[]) { for (int i = 0; i < n; i++) { cout << fixed << setprecision(1) << m[i].pav << " " << m[i].a << " " << " " << m[i].b << " " << m[i].r << endl; } }