#include <iostream>
#include <string>
#include <set>
//using namespace std; //don't use this
class runner{
public:
std::string name; //use string instead of array of char
float time;
void input(){
std::cout <<"\n Enter the name: ";
std::cin>> name;
std::cout <<"\n Enter the time taken to finish the race (mins): ";
std::cin>> time;
}
//overload operator< since we are using std::set
bool operator<( const runner &r ) const
{
return ( time < r.time );
}
};
int main(){
std::set<runner> runners; //use set instead of array
for(int i =0;i<5; i++){
runner tempRunner;
tempRunner.input();
runners.insert(tempRunner);
}
int i = 0;
//print out the details for 1st, 2nd and 3rd position as asked in the assignment question
for(const runner &tempRunner: runners)
{
if(i <3)
{
std::cout<<tempRunner.name <<" came: "<<i+1<<std::endl;
}
else{
break;
}
++i;
}
return 0;
}