Advertisement
treash

Untitled

Dec 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include<iostream>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     struct form{
  9.  
  10.         string city;
  11.         int free_places;
  12.         string ttime;
  13.  
  14.     } a[1000]; //массив структур
  15.  
  16.     int n;
  17.     struct form z;            //вспомогательная переменная для того, чтобы поменять два элемента структуры местами
  18.  
  19.     cout<<"Vvedite kol-vo svobodnih biletov: ";
  20.     cin>>n;
  21.     cout<<endl<<endl;
  22.  
  23.     for (int i=1; i<=n; i++){
  24.         cout<<"Vvedite pynct naznacheniya:"<<endl;
  25.         cin>>a[i].city;
  26.  
  27.         cout<<"Vvedite vremya otpravleniya poezda:"<<endl;
  28.         cin>>a[i].ttime;
  29.  
  30.         cout<<"Vvedite kolichestvo svobodnih mest:"<<endl;
  31.         cin>>a[i].free_places;
  32.        
  33.         cout<<endl;
  34.                                    
  35.     }
  36.  
  37.  
  38.     string f;
  39.     cout<<endl;
  40.     cout<<"Vvedite iskomi gorod: ";
  41.     cin>>f;                           //вводим искомый город
  42.  
  43.    
  44.     for(int i=1; i<=n-1; i++)                         //алгоритм сортировки "Пузырёк", на выходе получим отсортированный массив структур по убыванию кол-ва свободных мест
  45.         for (int j=1; j<=n-i; j++)
  46.             if (a[j].free_places<a[j+1].free_places){  
  47.                 z=a[j];                                //меняем  
  48.                 a[j]=a[j+1];                           //местами
  49.                 a[j+1]=z;                              //2 элемента
  50.             }
  51.  
  52.     cout<<endl<<"Poezda v poryadke ybivaniya kol-va svobodnih mest:"<<endl;
  53.  
  54.     for (int i=1; i<=n; i++)                                                  //выводим толлько те элементы массива, в которых город совпадает с заданным
  55.         if (a[i].city==f) cout<<a[i].ttime<<"  "<<a[i].free_places<<endl;
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement