Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct b {
- string Sname;
- string name;
- string classs;
- int school;
- };
- const int N = 4;
- int main() {
- b base[N];
- for (int i = 0; i < N; ++i) {
- cout << "Sname: ";
- cin >> base[i].Sname;
- cout << "name: ";
- cin >> base[i].name;
- cout << "classs: ";
- cin >> base[i].classs;
- cout << "school: ";
- cin >> base[i].school;
- cout << endl;
- }
- b bg;
- for (int i = 0; i < N; ++i) {
- for (int j = 0; j < N; ++j) {
- if (base[i].Sname.length() < base[j].Sname.length()) {
- bg = base[i];
- base[i] = base[j];
- base[j] = bg;
- }
- }
- }
- for (int i = 0; i < 3; ++i) {
- cout << endl << i + 1 << " :";
- cout << base[i].Sname << "\t";
- cout << base[i].name << base[i].classs;
- cout << "\t" << base[i].school;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment