fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. struct Elev {
  7. double medie;
  8. char nume[21];
  9. };
  10.  
  11. void sortare(int n, Elev elevi[30]) {
  12. for (int i = 0; i < n - 1; ++i) {
  13. for (int j = i + 1; j < n; ++j) {
  14. if (elevi[i].medie > elevi[j].medie ||
  15. (elevi[i].medie == elevi[j].medie && strcmp(elevi[i].nume, elevi[j].nume) > 0)) {
  16. Elev temp = elevi[i];
  17. elevi[i] = elevi[j];
  18. elevi[j] = temp;
  19. }
  20. }
  21. }
  22. }
  23.  
  24. int main() {
  25. int n = 4;
  26. Elev elevi[30] = {
  27. {8.00, "Popescu Ioana"},
  28. {5.00, "Popescu Dani"},
  29. {8.79, "Cristescu Aurel"},
  30. {6.98, "Cristescu Ioan"}
  31. };
  32.  
  33. sortare(n, elevi);
  34.  
  35. cout << "Clasamentul elevilor:\n";
  36. for (int i = 0; i < n; ++i) {
  37. cout << fixed << setprecision(2) << elevi[i].medie << " " << elevi[i].nume << endl;
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5248KB
stdin
Standard input is empty
stdout
Clasamentul elevilor:
5.00 Popescu Dani
6.98 Cristescu Ioan
8.00 Popescu Ioana
8.79 Cristescu Aurel