fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class SinhVien{
  5. private:
  6. string msv, ten, lop, email;
  7. public:
  8. friend istream& operator >> (istream &in, SinhVien &a);
  9. friend ostream& operator << (ostream &out, SinhVien a);
  10. string getLOP();
  11. string getMA();
  12. };
  13.  
  14.  
  15. istream& operator >> (istream &in , SinhVien &a){
  16. getline(in, a.msv);
  17. getline(in, a.ten);
  18. getline(in, a.lop);
  19. getline(in, a.email);
  20. return in;
  21. }
  22.  
  23. ostream& operator << (ostream &out, SinhVien a){
  24. out << a.msv << " " << a.ten << " " << a.lop << " " << a.email << endl;
  25. return out;
  26. }
  27.  
  28. string SinhVien::getLOP(){
  29. return this->lop;
  30. }
  31. string SinhVien::getMA(){
  32. return this->msv;
  33. }
  34.  
  35. bool cmp(SinhVien a, SinhVien b){
  36. if(a.getLOP()==b.getLOP()){
  37. return a.getMA() < b.getMA();
  38. }
  39. return a.getLOP() < b.getLOP();
  40. }
  41.  
  42. void sapxep(SinhVien ds[], int n){
  43. sort(ds,ds+n,cmp);
  44. }
  45.  
  46. int main(){
  47. int n; cin >> n;
  48. cin.ignore();
  49. SinhVien a[1001];
  50. for(int i = 0; i < n; i++) cin >> a[i];
  51. sapxep(a,n);
  52. for(int i = 0; i < n; i++) cout << a[i];
  53. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty