Advertisement
Spocoman

03. Flowers

Sep 5th, 2023 (edited)
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int chrysanthemums, roses, tulips;
  7.     cin >> chrysanthemums >> roses >> tulips;
  8.  
  9.     string season, holiday;
  10.     cin >> season >> holiday;
  11.  
  12.     double chrysanthemumPrice;
  13.     double rosePrice;
  14.     double tulipPrice;
  15.  
  16.     if (season == "Spring" || season == "Summer") {
  17.         chrysanthemumPrice = 2.00;
  18.         rosePrice = 4.10;
  19.         tulipPrice = 2.50;
  20.     }
  21.     else {
  22.         chrysanthemumPrice = 3.75;
  23.         rosePrice = 4.50;
  24.         tulipPrice = 4.15;
  25.     }
  26.    
  27.     double totalSum = chrysanthemums * chrysanthemumPrice + roses * rosePrice + tulips * tulipPrice;
  28.    
  29.     if (holiday == "Y") {
  30.         totalSum *= 1.15;
  31.     }
  32.  
  33.     if (tulips > 7 && season == "Spring") {
  34.         totalSum *= 0.95;
  35.     }
  36.  
  37.     if (roses >= 10 && season == "Winter") {
  38.         totalSum *= 0.90;
  39.     }
  40.    
  41.     if (chrysanthemums + roses + tulips > 20) {
  42.         totalSum *= 0.80;
  43.     }
  44.    
  45.     printf("%.2f\n", totalSum + 2);
  46.  
  47.     return 0;
  48. }
  49.  
  50. Решение с тернарен оператор:
  51.  
  52. #include <iostream>
  53.  
  54. using namespace std;
  55.  
  56. int main() {
  57.     int chrysanthemums, roses, tulips;
  58.     cin >> chrysanthemums >> roses >> tulips;
  59.  
  60.     string season, holiday;
  61.     cin >> season >> holiday;
  62.  
  63.     double chrysanthemumPrice = season == "Spring" || season == "Summer" ? 2.00 : 3.75;
  64.     double rosePrice = season == "Spring" || season == "Summer" ? 4.10 : 4.50;
  65.     double tulipPrice = season == "Spring" || season == "Summer" ? 2.50 : 4.15;
  66.    
  67.     double totalSum = (chrysanthemums * chrysanthemumPrice + roses * rosePrice + tulips * tulipPrice) * (holiday == "Y" ? 1.15 : 1);
  68.     totalSum *= tulips > 7 && season == "Spring" ? 0.95 : roses >= 10 && season == "Winter" ? 0.90 : 1;
  69.     totalSum *= chrysanthemums + roses + tulips > 20 ? 0.80 : 1;
  70.    
  71.     printf("%.2f\n", totalSum + 2);
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement