7
gorazd
c_cpp
a month ago
1.7 kB
2
Indexable
1kolok_OOP
#include <iostream> #include <cstring> #include <iomanip> using namespace std; struct Vozenje { char name[100]; int minutes; float price; int studentSale; }; struct ZabavenPark { char name[100]; char location[100]; Vozenje rides[100]; int numberOfRides; void print() { cout<<name<<" "<<location<<endl; for (int i = 0; i<numberOfRides; i++) { cout<<rides[i].name<<" "<<rides[i].minutes<<" "<<fixed<<setprecision(2)<<rides[i].price<<endl; } } }; void najdobar_park(ZabavenPark *zs, int n) { ZabavenPark najdobar; int max = 0; int vreme = 0; for (int i = 0; i<n; i++) { int _max = 0; int _vreme = 0; for (int j = 0; j<zs[i].numberOfRides; j++) { _vreme += zs[i].rides[j].minutes; if (zs[i].rides[j].studentSale==1) _max++; } if (_max>max) { max = _max; vreme = _vreme; najdobar = zs[i]; } else if (_max==max and max!=0) { if (_vreme>vreme) najdobar = zs[i]; } } cout<<"Najdobar park: "<<najdobar.name<<" "<<najdobar.location<<endl; } int main() { int n; cin>>n; //number of zabavenPark ZabavenPark zp[n]; for (int i = 0; i<n; i++) { cin>>zp[i].name>>zp[i].location; cin>>zp[i].numberOfRides; for (int j = 0; j<zp[i].numberOfRides; j++) { cin>>zp[i].rides[j].name; cin>>zp[i].rides[j].minutes; cin>>zp[i].rides[j].price; cin>>zp[i].rides[j].studentSale; } zp[i].print(); } najdobar_park(zp, n); }
Editor is loading...
Leave a Comment