Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- typedef struct
- {
- char nume[20], prenume[20];
- unsigned nrabs, absmot;
- unsigned nota;
- } ELEV;
- int main()
- {
- ELEV e[100];
- int n;
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> e[i].nume >> e[i].prenume >> e[i].nrabs >> e[i].absmot;
- for (int i = 0; i < n; i++)
- {
- int nemot = e[i].nrabs - e[i].absmot;
- if (nemot > 50)
- e[i].nota = 4;
- else
- e[i].nota = 10 - nemot / 10;
- }
- int sortat = 0;
- while (!sortat)
- {
- sortat = 1;
- for (int i = 0; i < n - 1; i++)
- if (e[i].nota < e[i + 1].nota)
- {
- ELEV aux = e[i];
- e[i] = e[i + 1];
- e[i + 1] = aux;
- sortat = 0;
- }
- else if (e[i].nota == e[i + 1].nota)
- {
- if (!strcmp(e[i].nume, e[i + 1].nume))
- {
- if (strcmp(e[i].prenume, e[i + 1].prenume) > 0)
- {
- ELEV aux = e[i];
- e[i] = e[i + 1];
- e[i + 1] = aux;
- sortat = 0;
- }
- }
- else if (strcmp(e[i].nume, e[i + 1].nume) > 0)
- {
- ELEV aux = e[i];
- e[i] = e[i + 1];
- e[i + 1] = aux;
- sortat = 0;
- }
- }
- }
- cout << "lista elevi: " << endl;
- for (int i = 0; i < n; i++)
- cout << e[i].nume << ' ' << e[i].prenume << ' ' << e[i].nota << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement