fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <string>
  4. using namespace std;
  5. class Athlete {
  6. private:
  7. string name;
  8. double time;
  9. public:
  10. Athlete() : name(""), time(0) {}
  11. Athlete(string n, double t) {
  12. name = n;
  13. time = t;
  14. }
  15. string getName() const {
  16. return name;
  17. }
  18.  
  19. double getTime() const {
  20. return time;
  21. }
  22.  
  23. bool operator<(const Athlete& other) const {
  24. if (time == other.time)
  25. return name < other.name;
  26. return time < other.time;
  27. }
  28. };
  29. Athlete findFastest(const set<Athlete>& athletes) {
  30. return *athletes.begin();
  31. }
  32. void printResults(const set<pair<int, Athlete>>& results,
  33. int startPlace,
  34. int endPlace) {
  35.  
  36.  
  37. for (const auto& p : results) {
  38. if (p.first >= startPlace && p.first <= endPlace) {
  39. cout << p.first<<endl<< p.second.getName()<<endl<< p.second.getTime()
  40. ;
  41. }
  42. }
  43. }
  44. int main() {
  45. set<Athlete> athletes;
  46.  
  47. athletes.insert(Athlete("Іван", 11.2));
  48. athletes.insert(Athlete("Петро", 10.8));
  49. athletes.insert(Athlete("Олег", 12.1));
  50. athletes.insert(Athlete("Максим", 10.5));
  51.  
  52.  
  53. for (const auto& athlete : athletes) {
  54. cout << athlete.getName()
  55. << " - " << athlete.getTime()
  56. << " с\n";
  57. }
  58.  
  59. Athlete fastest = findFastest(athletes);
  60.  
  61. cout << fastest.getName()
  62. << " (" << fastest.getTime()
  63. << " с)\n";
  64.  
  65. set<pair<int, Athlete>> results;
  66.  
  67. results.insert({1, Athlete("Максим", 10.5)});
  68. results.insert({2, Athlete("Петро", 10.8)});
  69. results.insert({3, Athlete("Іван", 11.2)});
  70. results.insert({4, Athlete("Олег", 12.1)});
  71. printResults(results, 1, 100);
  72.  
  73. int startPlace, endPlace;
  74.  
  75.  
  76. cin >> startPlace;
  77.  
  78. cin >> endPlace;
  79.  
  80. printResults(results, startPlace, endPlace);
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Максим - 10.5 с
Петро - 10.8 с
Іван - 11.2 с
Олег - 12.1 с
Максим (10.5 с)
1
Максим
10.52
Петро
10.83
Іван
11.24
Олег
12.11
Максим
10.52
Петро
10.83
Іван
11.24
Олег
12.1