fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct student {
  5. char name[21];
  6. char surname[21];
  7. char letter;
  8. int Class;
  9. char date[9];
  10. };
  11.  
  12. bool operator > (const student & a,
  13. const student & b) {
  14. bool res = false;
  15. bool tmp = true;
  16. if (a.Class > b.Class) res = true;
  17. else if (a.Class == b.Class) {
  18. if (a.letter > b.letter) res = true;
  19. else if (a.letter == b.letter) {
  20. for (int i = 0; i < 21; i++) {
  21. if (a.surname[i] < b.surname[i]) {
  22. tmp = false;
  23. break;
  24. } else if (a.surname[i] > b.surname[i]) {
  25. tmp = true;
  26. break;
  27. }
  28. }
  29. if (tmp) res = true;
  30. }
  31. }
  32. return res;
  33. };
  34.  
  35. int main() {
  36. int n;
  37. cin >> n;
  38. student *a = new student[n];
  39. for (int i = 0; i < n; i++) {
  40. cin >> a[i].surname >> a[i].name >> a[i].Class >> a[i].letter >> a[i].date;
  41. }
  42. for (int k = 2; k <= n; k++) {
  43. for (int i = 0; i <= n - k; i++) {
  44. if (a[i] > a[i + 1]) {
  45. swap(a[i], a[i + 1]);
  46. }
  47. }
  48. }
  49. for (int i = 0; i < n; i++) {
  50. cout << a[i].Class << a[i].letter << " " << a[i].surname << " " << a[i].name << " " << a[i].date << endl;
  51. }
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 15240KB
stdin
3
Sidorov
Sidor
9A
20.07.93
Petrov
Petr
10B
23.10.92
Ivanov
Ivan
9A
10.04.93
stdout
9A Ivanov Ivan 10.04.93
9A Sidorov Sidor 20.07.93
10B Petrov Petr 23.10.92