Advertisement
Spocoman

07. School Camp

Sep 6th, 2023
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string season, group;
  8.     cin >> season >> group;
  9.  
  10.     int people, nights;
  11.     cin >> people >> nights;
  12.  
  13.     double pricePerNight;
  14.     string sport;
  15.  
  16.     if (season == "Winter") {
  17.         if (group == "boys") {
  18.             pricePerNight = 9.60;
  19.             sport = "Judo";
  20.         }
  21.         else if (group == "girls") {
  22.             pricePerNight = 9.60;
  23.             sport = "Gymnastics";
  24.         }
  25.         else if (group == "mixed") {
  26.             pricePerNight = 10;
  27.             sport = "Ski";
  28.         }
  29.     }
  30.     else if (season == "Spring") {
  31.         if (group == "boys") {
  32.             pricePerNight = 7.20;
  33.             sport = "Tennis";
  34.         }
  35.         else if (group == "girls") {
  36.             pricePerNight = 7.20;
  37.             sport = "Athletics";
  38.         }
  39.         else if (group == "mixed") {
  40.             pricePerNight = 9.50;
  41.             sport = "Cycling";
  42.         }
  43.     }
  44.     else {
  45.         if (group == "boys") {
  46.             pricePerNight = 15;
  47.             sport = "Football";
  48.         }
  49.         else if (group == "girls") {
  50.             pricePerNight = 15;
  51.             sport = "Volleyball";
  52.         }
  53.         else if (group == "mixed") {
  54.             pricePerNight = 20;
  55.             sport = "Swimming";
  56.         }
  57.     }
  58.  
  59.     if (people >= 10 && people < 20) {
  60.         pricePerNight *= 0.95;
  61.     }
  62.     else if (people >= 20 && people < 50) {
  63.         pricePerNight *= 0.85;
  64.     }
  65.     else if (people >= 50) {
  66.         pricePerNight *= 0.50;
  67.     }
  68.  
  69.     double totalSum = pricePerNight * nights * people;
  70.  
  71.     cout << sport << " " << fixed << setprecision(2) << totalSum << " lv." << endl;
  72.  
  73.     return 0;
  74. }
  75.  
  76. Решение с тернарен оператор:
  77.  
  78. #include <iostream>
  79. #include <iomanip>
  80.  
  81. using namespace std;
  82.  
  83. int main() {
  84.     string season, group;
  85.     cin >> season >> group;
  86.  
  87.     int people, nights;
  88.     cin >> people >> nights;
  89.  
  90.     double pricePerNight =
  91.         season == "Winter" ? (group == "mixed" ? 10 : 9.60) :
  92.         season == "Spring" ? (group == "mixed" ? 9.50 : 7.20) : (group == "mixed" ? 20 : 15);
  93.  
  94.     pricePerNight *=
  95.         people >= 10 && people < 20 ? 0.95 :
  96.         people >= 20 && people < 50 ? 0.85 :
  97.         people >= 50 ? 0.50 : 1;
  98.  
  99.     string sport =
  100.         season == "Winter" ? (group == "boys" ? "Judo" : group == "girls" ? "Gymnastics" : "Ski") :
  101.         season == "Spring" ? (group == "boys" ? "Tennis" : group == "girls" ? "Athletics" : "Cycling") :
  102.         (group == "boys" ? "Football" : group == "girls" ? "Volleyball" : "Swimming");
  103.  
  104.     double totalSum = pricePerNight * nights * people;
  105.  
  106.     cout << sport << " " << fixed << setprecision(2) << totalSum << " lv." << endl;
  107.  
  108.     return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement