Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6. struct AEROFLOT {
  7.   string NCity;
  8.   int Num;
  9.   string Type;
  10. };
  11.  
  12. int main()
  13. {
  14.   AEROFLOT Flot[7];
  15.  
  16.   bool chek = false;
  17.  
  18.   setlocale(LC_ALL, "Russian");
  19.   for (int i = 0; i < 7; i++){
  20.     cout << "Введите номер:";
  21.     cin >> Flot[i].Num;
  22.     cout << "Введите тип самолета:";
  23.     cin >> Flot[i].Type;
  24.     cout << "Введите город:";
  25.     cin >> Flot[i].NCity;
  26.     cout << "-------------------------------------\n";
  27.  
  28.   }
  29.  
  30.   int tempN; string tempS;
  31.   for (int i = 0; i < 7 - 1; i++) {
  32.     for (int j = 0; j < 7 - i - 1; j++) {
  33.       if (Flot[j].Num > Flot[j + 1].Num) {
  34.         // меняем элементы местами
  35.         tempN = Flot[j].Num;
  36.         Flot[j].Num = Flot[j + 1].Num;
  37.         Flot[j + 1].Num = tempN;
  38.  
  39.         tempS = Flot[j].NCity;
  40.         Flot[j].NCity = Flot[j + 1].NCity;
  41.         Flot[j + 1].NCity = tempS;
  42.  
  43.         tempS = Flot[j].Type;
  44.         Flot[j].Type = Flot[j + 1].Type;
  45.         Flot[j + 1].Type = tempS;
  46.       }
  47.     }
  48.   }
  49.  
  50.   for (int i = 0; i < 7; i++) {
  51.     cout << "Номер самолетa: " << Flot[i].Num << "\t" << "Тип самолетa: " << Flot[i].Type <<"\t"<< "Город назначения:" << Flot[i].NCity << endl;
  52.   }
  53.  
  54.  
  55.   for (int i = 0; i < 7; i++) {
  56.     for (int j = i+1; j < 7; j++) {
  57.       if (Flot[i].NCity == Flot[j].NCity && i != j) {
  58.         cout << "Номера самолетов летящих в один город: " << Flot[i].Num << ", " << Flot[j].Num << "\n" << "Типы самолетов: " << Flot[i].Type << ", " << Flot[j].Type << endl;
  59.         chek = true;
  60.       }
  61.     }
  62.   }
  63.  
  64.   if (!chek){cout << "Нет самолетов, летящих в один город!!" << endl;}
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement