Advertisement
Spocoman

Travel Agency

Sep 22nd, 2023
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string town, pack, vip;
  8.     cin >> town >> pack >> vip;
  9.  
  10.     int days;
  11.     cin >> days;
  12.  
  13.     if (days > 7) {
  14.         days--;
  15.     }
  16.  
  17.     double dayPrice = 0;
  18.  
  19.     if (town == "Bansko" || town == "Borovets") {
  20.         if (pack == "withEquipment") {
  21.             dayPrice = 100;
  22.             if (vip == "yes") {
  23.                 dayPrice *= 0.90;
  24.             }
  25.         }
  26.         else if (pack == "noEquipment") {
  27.             dayPrice = 80;
  28.             if (vip == "yes") {
  29.                 dayPrice *= 0.95;
  30.             }
  31.         }
  32.     }
  33.     else if (town == "Varna" || town == "Burgas") {
  34.         if (pack == "withBreakfast") {
  35.             dayPrice = 130;
  36.             if (vip == "yes") {
  37.                 dayPrice *= 0.88;
  38.             }
  39.         }
  40.         else if (pack == "noBreakfast") {
  41.             dayPrice = 100;
  42.             if (vip == "yes") {
  43.                 dayPrice *= 0.93;
  44.             }
  45.         }
  46.     }
  47.  
  48.     if (days < 1) {
  49.         cout << "Days must be positive number!\n";
  50.     }
  51.     else if (dayPrice > 0) {
  52.         printf("The price is %.2flv! Have a nice time!", dayPrice * days);
  53.     }
  54.     else  {
  55.         cout << "Invalid input!\n";
  56.     }
  57.  
  58.     return 0;
  59. }
  60.  
  61. Решение с тернарен оператор:
  62.  
  63. #include <iostream>
  64. #include <string>
  65.  
  66. using namespace std;
  67.  
  68. int main() {
  69.     string town, pack, vip;
  70.     cin >> town >> pack >> vip;
  71.  
  72.     int days;
  73.     cin >> days;
  74.  
  75.     if (days > 7) {
  76.         days--;
  77.     }
  78.  
  79.     double dayPrice =
  80.         town == "Bansko" || town == "Borovets" ?
  81.         (pack == "withEquipment" ? 100 * (vip == "yes" ? 0.90 : 1) : pack == "noEquipment" ? 80 * (vip == "yes" ? 0.95 : 1) : 0) :
  82.         town == "Varna" || town == "Burgas" ?
  83.         (pack == "withBreakfast" ? 130 * (vip == "yes" ? 0.88 : 1) : pack == "noBreakfast" ? 100 * (vip == "yes" ? 0.93 : 1) : 0) : 0;
  84.  
  85.     days < 1 ? printf("Days must be positive number!\n") :
  86.         dayPrice > 0 ? printf("The price is %.2flv! Have a nice time!", dayPrice * days) :
  87.         printf("Invalid input!\n");
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement