Advertisement
STANAANDREY

6/59

Nov 13th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. typedef struct
  6. {
  7.     char nume[20], prenume[20];
  8.     unsigned nrabs, absmot;
  9.     unsigned nota;
  10. } ELEV;
  11.  
  12. int main()
  13. {
  14.     ELEV e[100];
  15.     int n;
  16.     cin >> n;
  17.  
  18.     for (int i = 0; i < n; i++)
  19.         cin >> e[i].nume >> e[i].prenume >> e[i].nrabs >> e[i].absmot;
  20.  
  21.     for (int i = 0; i < n; i++)
  22.     {
  23.         int nemot = e[i].nrabs - e[i].absmot;
  24.         if (nemot > 50)
  25.             e[i].nota = 4;
  26.         else
  27.             e[i].nota = 10 - nemot / 10;
  28.     }
  29.  
  30.     int sortat = 0;
  31.     while (!sortat)
  32.     {
  33.         sortat = 1;
  34.         for (int i = 0; i < n - 1; i++)
  35.             if (e[i].nota < e[i + 1].nota)
  36.             {
  37.                 ELEV aux = e[i];
  38.                 e[i] = e[i + 1];
  39.                 e[i + 1] = aux;
  40.                 sortat = 0;
  41.             }
  42.             else if (e[i].nota == e[i + 1].nota)
  43.             {
  44.                 if (!strcmp(e[i].nume, e[i + 1].nume))
  45.                 {
  46.                     if (strcmp(e[i].prenume, e[i + 1].prenume) > 0)
  47.                     {
  48.                         ELEV aux = e[i];
  49.                         e[i] = e[i + 1];
  50.                         e[i + 1] = aux;
  51.                         sortat = 0;
  52.                     }
  53.                 }
  54.                 else if (strcmp(e[i].nume, e[i + 1].nume) > 0)
  55.                 {
  56.                     ELEV aux = e[i];
  57.                     e[i] = e[i + 1];
  58.                     e[i + 1] = aux;
  59.                     sortat = 0;
  60.                 }
  61.             }
  62.  
  63.     }
  64.  
  65.     cout << "lista elevi: " << endl;
  66.     for (int i = 0; i < n; i++)
  67.         cout << e[i].nume << ' ' << e[i].prenume << ' ' << e[i].nota << endl;
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement