fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 20;
  6. const int MAX_STUDENTS = 30;
  7.  
  8. struct Elev {
  9. double medie;
  10. char nume[MAX_SIZE + 1];
  11. };
  12.  
  13. void sortare(int n, Elev elevi[]) {
  14. for (int i = 0; i < n - 1; ++i) {
  15. for (int j = i + 1; j < n; ++j) {
  16. int changed = 0;
  17. if (elevi[i].medie > elevi[j].medie) {
  18. int medie = elevi[j].medie;
  19. elevi[j].medie = elevi[i].medie;
  20. elevi[i].medie = medie;
  21. changed = 1;
  22. }
  23. if ((changed && elevi[i].medie < elevi[j].medie) || (elevi[i].medie == elevi[j].medie && strcmp(elevi[i].nume, elevi[j].nume) > 0)) {
  24. char aux[MAX_SIZE + 1];
  25. strcpy(aux, elevi[j].nume);
  26. strcpy(elevi[j].nume, elevi[i].nume);
  27. strcpy(elevi[i].nume, aux);
  28. }
  29. }
  30. }
  31. }
  32.  
  33. int main() {
  34. Elev elevi[MAX_STUDENTS];
  35. int n;
  36. cin >> n;
  37. for (int i = 0; i < n; ++i) {
  38. cin >> elevi[i].medie;
  39. cin.getline(elevi[i].nume, MAX_SIZE + 1);
  40. }
  41. sortare(n, elevi);
  42. for (int i = 0; i < n; ++i) {
  43. cout << elevi[i].medie << ' ' << elevi[i].nume << '\n';
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 5280KB
stdin
2
8.34 Ionescu
8.12 Vlad
stdout
8  Vlad
8.34  Ionescu