Advertisement
Spocoman

07. Hotel Room

Sep 5th, 2023
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string month;
  7.     cin >> month;
  8.  
  9.     int night;
  10.     cin >> night;
  11.  
  12.     double apartmentPrice;
  13.     double studioPrice;
  14.  
  15.     if (month == "May" || month == "October") {
  16.         apartmentPrice = 65;
  17.         studioPrice = 50;
  18.  
  19.         if (night > 7 && night <= 14) {
  20.             studioPrice *= 0.95;
  21.         }
  22.         else if (night > 14) {
  23.             studioPrice *= 0.70;
  24.         }
  25.     }
  26.     else if (month == "June" || month == "September") {
  27.         apartmentPrice = 68.70;
  28.         studioPrice = 75.20;
  29.  
  30.         if (night > 14) {
  31.             studioPrice *= 0.80;
  32.         }
  33.     }
  34.     else if (month == "July" || month == "August") {
  35.         apartmentPrice = 77;
  36.         studioPrice = 76;
  37.     }
  38.  
  39.     if (night > 14) {
  40.         apartmentPrice *= 0.9;
  41.     }
  42.  
  43.     cout.setf(ios::fixed);
  44.     cout.precision(2);
  45.  
  46.     cout << "Apartment: " << apartmentPrice * night << " lv.\n" << "Studio: " << studioPrice * night << " lv.\n";
  47.  
  48.     return 0;
  49. }
  50.  
  51. Решение с тернарен оператор:
  52.  
  53. #include <iostream>
  54.  
  55. using namespace std;
  56.  
  57. int main() {
  58.     string month;
  59.     cin >> month;
  60.  
  61.     int night;
  62.     cin >> night;
  63.  
  64.     double apartmentPrice;
  65.     double studioPrice;
  66.  
  67.     if (month == "May" || month == "October") {
  68.         apartmentPrice = 65;
  69.         studioPrice = 50 * (night > 7 && night <= 14 ? 0.95 : night > 14 ? 0.70 : 1);
  70.     }
  71.     else if (month == "June" || month == "September") {
  72.         apartmentPrice = 68.70;
  73.         studioPrice = 75.20 * (night > 14 ? 0.80 : 1);
  74.     }
  75.     else if (month == "July" || month == "August") {
  76.         apartmentPrice = 77;
  77.         studioPrice = 76;
  78.     }
  79.     apartmentPrice *= night > 14 ? 0.90 : 1;
  80.  
  81.     cout.setf(ios::fixed);
  82.     cout.precision(2);
  83.  
  84.     cout << "Apartment: " << apartmentPrice * night << " lv.\n" << "Studio: " << studioPrice * night << " lv.\n";
  85.  
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement