Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<iostream>
- #include<string>
- using namespace std;
- int main(){
- struct form{
- string city;
- int free_places;
- string ttime;
- } a[1000]; //массив структур
- int n;
- struct form z; //вспомогательная переменная для того, чтобы поменять два элемента структуры местами
- cout<<"Vvedite kol-vo svobodnih biletov: ";
- cin>>n;
- cout<<endl<<endl;
- for (int i=1; i<=n; i++){
- cout<<"Vvedite pynct naznacheniya:"<<endl;
- cin>>a[i].city;
- cout<<"Vvedite vremya otpravleniya poezda:"<<endl;
- cin>>a[i].ttime;
- cout<<"Vvedite kolichestvo svobodnih mest:"<<endl;
- cin>>a[i].free_places;
- cout<<endl;
- }
- string f;
- cout<<endl;
- cout<<"Vvedite iskomi gorod: ";
- cin>>f; //вводим искомый город
- for(int i=1; i<=n-1; i++) //алгоритм сортировки "Пузырёк", на выходе получим отсортированный массив структур по убыванию кол-ва свободных мест
- for (int j=1; j<=n-i; j++)
- if (a[j].free_places<a[j+1].free_places){
- z=a[j]; //меняем
- a[j]=a[j+1]; //местами
- a[j+1]=z; //2 элемента
- }
- cout<<endl<<"Poezda v poryadke ybivaniya kol-va svobodnih mest:"<<endl;
- for (int i=1; i<=n; i++) //выводим толлько те элементы массива, в которых город совпадает с заданным
- if (a[i].city==f) cout<<a[i].ttime<<" "<<a[i].free_places<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement