x2311

Untitled

Jan 12th, 2022
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct b {
  6.     string Sname;
  7.     string name;
  8.     string classs;
  9.     int school;
  10. };
  11. const int N = 4;
  12.  
  13. int main() {
  14.     b base[N];
  15.     for (int i = 0; i < N; ++i) {
  16.         cout << "Sname: ";
  17.         cin >> base[i].Sname;
  18.         cout << "name: ";
  19.         cin >> base[i].name;
  20.         cout << "classs: ";
  21.         cin >> base[i].classs;
  22.         cout << "school: ";
  23.         cin >> base[i].school;
  24.  
  25.         cout << endl;
  26.     }
  27.  
  28.     b bg;
  29.     for (int i = 0; i < N; ++i) {
  30.         for (int j = 0; j < N; ++j) {
  31.             if (base[i].Sname.length() < base[j].Sname.length()) {
  32.                 bg = base[i];
  33.                 base[i] = base[j];
  34.                 base[j] = bg;
  35.             }
  36.         }
  37.     }
  38.  
  39.  
  40.     for (int i = 0; i < 3; ++i) {
  41.         cout << endl << i + 1 << " :";
  42.         cout << base[i].Sname << "\t";
  43.         cout << base[i].name << base[i].classs;
  44.         cout << "\t" << base[i].school;
  45.     }
  46.  
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment