fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. class SinhVien {
  6. private:
  7. string id, name, id_class, mail;
  8.  
  9. public:
  10. SinhVien() {}
  11. string getId() { return id; }
  12. string getIdClass() { return id_class; }
  13. friend istream& operator>>(istream& in, SinhVien& sv);
  14. friend ostream& operator<<(ostream& out, SinhVien sv);
  15. };
  16.  
  17. bool cmp(SinhVien a, SinhVien b) {
  18. if (a.getIdClass() == b.getIdClass()) {
  19. return a.getId() < b.getId();
  20. }
  21. return a.getIdClass() < b.getIdClass();
  22. }
  23.  
  24. istream& operator>>(istream& in, SinhVien& sv) {
  25. getline(in, sv.id);
  26. getline(in, sv.name);
  27. getline(in, sv.id_class);
  28. getline(in, sv.mail);
  29. return in;
  30. }
  31.  
  32. ostream& operator<<(ostream& out, SinhVien sv) {
  33. out << sv.id << " " << sv.name << " " << sv.id_class << " " << sv.mail;
  34. return out;
  35. }
  36.  
  37. int main() {
  38. cin.tie(NULL);
  39. cout.tie(NULL);
  40. ios_base::sync_with_stdio(false);
  41.  
  42. int N;
  43. cin >> N;
  44. cin.ignore();
  45. SinhVien ds[N];
  46.  
  47. for (int i = 0; i < N; i++) {
  48. cin >> ds[i];
  49. }
  50.  
  51. sort(ds, ds + N, cmp);
  52.  
  53. for (int i = 0; i < N; i++) {
  54. cout << ds[i] << endl;
  55. }
  56.  
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0.02s 5288KB
stdin
Standard input is empty
stdout