fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. #define int long long
  4. #define faster() ios::sync_with_stdio(false); cin.tie(nullptr) ; cout.tie(nullptr);
  5. #define endl "\n"
  6.  
  7. struct SinhVien{
  8. string name ;
  9. string maSV ;
  10. string ten;
  11. string ho ;
  12. string ho2 ;
  13. double gpa ;
  14. };
  15.  
  16. bool cmp(SinhVien a, SinhVien b){
  17. if(a.gpa == b.gpa){
  18. if(a.name == b.name){
  19. return a.ho < b.ho ;
  20. }
  21. else return a.name < b.name ;
  22. }
  23. else return a.gpa > b.gpa ;
  24. }
  25.  
  26. void solve(){
  27. int n;
  28. cin >> n;
  29. cin.ignore(); // Thêm dòng này để bỏ qua ký tự newline còn sót trong buffer
  30. vector<SinhVien> a(n);
  31. for(int i = 0 ; i < n ; i++){
  32. getline(cin, a[i].maSV);
  33. getline(cin ,a[i].name);
  34. cin >> a[i].gpa ;
  35. cin.ignore(); // Bỏ qua newline sau khi nhập GPA
  36. string tmp = a[i].name ;
  37. stringstream ss(tmp);
  38. string word = "";
  39. vector<string> v;
  40. while(ss >> word){
  41. v.push_back(word);
  42. }
  43. a[i].ten = v[v.size() - 1];
  44. for(int j = 0 ; j < v.size() - 1 ; j++){
  45. a[i].ho += v[j];
  46. }
  47. }
  48.  
  49. sort(a.begin(), a.end(), cmp);
  50. for(int i = 0 ; i < n ; i++){
  51. cout << a[i].maSV << " " << a[i].name << " ";
  52. if(ceil(a[i].gpa) == floor(a[i].gpa))
  53. cout << (int) a[i].gpa << endl;
  54. else
  55. cout << a[i].gpa << endl;
  56. }
  57. }
  58.  
  59. signed main(){
  60. faster();
  61. int test = 1 ;
  62. while(test--){
  63. solve();
  64. }
  65. }
  66.  
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty