fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct student {
  6. string name, surname;
  7. char letter;
  8. int Class;
  9. string date;
  10. };
  11.  
  12. bool operator > (const student &a, const student &b) {
  13. bool res = false;
  14. if (a.Class > b.Class) res = true;
  15. else if (a.Class == b.Class) {
  16. if (a.letter > b.letter) res = true;
  17. else if (a.letter == b.letter) {
  18. if (a.surname > b.surname) res = true;
  19. }
  20. }
  21. return res;
  22. };
  23.  
  24. int main() {
  25. int n;
  26. cin >> n;
  27. student *a = new student[n];
  28. for (int i = 0; i < n; i++) {
  29. cin >> a[i].surname >> a[i].name >> a[i].Class >> a[i].letter >> a[i].date;
  30. }
  31. for (int k = 2; k <= n; k++) {
  32. for (int i = 0; i <= n - k; i++) {
  33. if (a[i] > a[i + 1]) {
  34. swap(a[i], a[i + 1]);
  35. }
  36. }
  37. }
  38. for (int i = 0; i < n; i++) {
  39. cout << a[i].Class << a[i].letter << " " << a[i].surname << " " << a[i].name << " " << a[i].date << endl;
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 15240KB
stdin
1
Zadorozhniy
Pavel
11A
20.03.02
stdout
11A Zadorozhniy Pavel 20.03.02