Advertisement
Spocoman

World Snooker Championship

Sep 22nd, 2023 (edited)
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string stageOfTheChampionship, typesOfTickets;
  8.     getline(cin, stageOfTheChampionship);
  9.     cin >> typesOfTickets;
  10.  
  11.     int ticketCount;
  12.     cin >> ticketCount;
  13.  
  14.     string selfieWithTheTrophy;
  15.     cin >> selfieWithTheTrophy;
  16.  
  17.     double ticketPrice = 0;
  18.  
  19.     if (stageOfTheChampionship == "Quarter final") {
  20.         if (typesOfTickets == "Standard") {
  21.             ticketPrice = 55.50;
  22.         }
  23.         else if (typesOfTickets == "Premium") {
  24.             ticketPrice = 105.20;
  25.         }
  26.         else if (typesOfTickets == "VIP") {
  27.             ticketPrice = 118.90;
  28.         }
  29.     }
  30.     else if (stageOfTheChampionship == "Semi final") {
  31.         if (typesOfTickets == "Standard") {
  32.             ticketPrice = 75.88;
  33.         }
  34.         else if (typesOfTickets == "Premium") {
  35.             ticketPrice = 125.22;
  36.         }
  37.         else if (typesOfTickets == "VIP") {
  38.             ticketPrice = 300.40;
  39.         }
  40.     }
  41.     else if (stageOfTheChampionship == "Final") {
  42.         if (typesOfTickets == "Standard") {
  43.             ticketPrice = 110.10;
  44.         }
  45.         else if (typesOfTickets == "Premium") {
  46.             ticketPrice = 160.66;
  47.         }
  48.         else if (typesOfTickets == "VIP") {
  49.             ticketPrice = 400.00;
  50.         }
  51.     }
  52.  
  53.     double totalPrice = ticketPrice * ticketCount;
  54.  
  55.     if (totalPrice > 4000) {
  56.         totalPrice *= 0.75;
  57.         selfieWithTheTrophy = "N";
  58.     }
  59.     else if (totalPrice > 2500) {
  60.         totalPrice *= 0.90;
  61.     }
  62.  
  63.     if (selfieWithTheTrophy == "Y") {
  64.         totalPrice += ticketCount * 40;
  65.     }
  66.  
  67.     printf("%.2f\n", totalPrice);
  68.  
  69.     return 0;
  70. }
  71.  
  72. Решение с тернарен оператор:
  73.  
  74. #include <iostream>
  75. #include <string>
  76.  
  77. using namespace std;
  78.  
  79. int main() {
  80.     string stageOfTheChampionship, typesOfTickets;
  81.     getline(cin, stageOfTheChampionship);
  82.     cin >> typesOfTickets;
  83.  
  84.     int ticketCount;
  85.     cin >> ticketCount;
  86.  
  87.     string selfieWithTheTrophy;
  88.     cin >> selfieWithTheTrophy;
  89.  
  90.     double totalPrice =
  91.         (stageOfTheChampionship == "Quarter final" ? (typesOfTickets == "Standard" ? 55.50 : typesOfTickets == "Premium" ? 105.20 : 118.90) :
  92.             stageOfTheChampionship == "Semi final" ? (typesOfTickets == "Standard" ? 75.88 : typesOfTickets == "Premium" ? 125.22 : 300.40) :
  93.             (typesOfTickets == "Standard" ? 110.10 : typesOfTickets == "Premium" ? 160.66 : 400.00)) * ticketCount;
  94.  
  95.     selfieWithTheTrophy = totalPrice > 4000 ? "No" : selfieWithTheTrophy;
  96.  
  97.     totalPrice = totalPrice * (totalPrice > 4000 ? 0.75 : totalPrice > 2500 ? 0.90 : 1) + (selfieWithTheTrophy == "Y" ? ticketCount * 40 : 0);
  98.  
  99.     printf("%.2f\n", totalPrice);
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement