Advertisement
Spocoman

05. Vacation

Sep 6th, 2023
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     double budget;
  8.     cin >> budget;
  9.  
  10.     string season;
  11.     cin >> season;
  12.  
  13.     string location = "";
  14.     string place = "";
  15.  
  16.     if (season == "Summer") {
  17.         location = "Alaska";
  18.     }
  19.     else {
  20.         location = "Morocco";
  21.     }
  22.    
  23.     if (budget <= 1000) {
  24.         if (season == "Summer") {
  25.             budget *= 0.65;
  26.         }
  27.         else {
  28.             budget *= 0.45;
  29.         }
  30.         place = "Camp";
  31.     }
  32.     else if (budget <= 3000) {
  33.  
  34.         if (season == "Summer") {
  35.             budget *= 0.8;
  36.         }
  37.         else {
  38.             budget *= 0.6;
  39.         }
  40.         place = "Hut";
  41.     }
  42.     else {
  43.         place = "Hotel";
  44.         budget *= 0.9;
  45.     }
  46.  
  47.     cout << location << " - "  << place << " - " << fixed << setprecision(2) << budget << endl;
  48.  
  49.     return 0;
  50. }
  51.  
  52. Решение с тернарен оператор:
  53.  
  54. #include <iostream>
  55. #include <iomanip>
  56.  
  57. using namespace std;
  58.  
  59. int main() {
  60.     double budget;
  61.     cin >> budget;
  62.  
  63.     string season;
  64.     cin >> season;
  65.  
  66.     string location = season == "Summer" ? "Alaska" : "Morocco";
  67.  
  68.     string place = budget <= 1000 ? "Camp" : budget <= 3000 ? "Hut" : "Hotel";
  69.  
  70.     budget *=
  71.         budget <= 1000 ? (season == "Summer" ? 0.65 : 0.45) :
  72.         budget <= 3000 ? (season == "Summer" ? 0.80 : 0.60) : 0.90;
  73.  
  74.     cout << location << " - "  << place << " - " << fixed << setprecision(2) << budget << endl;
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement