Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int chrysanthemums, roses, tulips;
- cin >> chrysanthemums >> roses >> tulips;
- string season, holiday;
- cin >> season >> holiday;
- double chrysanthemumPrice;
- double rosePrice;
- double tulipPrice;
- if (season == "Spring" || season == "Summer") {
- chrysanthemumPrice = 2.00;
- rosePrice = 4.10;
- tulipPrice = 2.50;
- }
- else {
- chrysanthemumPrice = 3.75;
- rosePrice = 4.50;
- tulipPrice = 4.15;
- }
- double totalSum = chrysanthemums * chrysanthemumPrice + roses * rosePrice + tulips * tulipPrice;
- if (holiday == "Y") {
- totalSum *= 1.15;
- }
- if (tulips > 7 && season == "Spring") {
- totalSum *= 0.95;
- }
- if (roses >= 10 && season == "Winter") {
- totalSum *= 0.90;
- }
- if (chrysanthemums + roses + tulips > 20) {
- totalSum *= 0.80;
- }
- printf("%.2f\n", totalSum + 2);
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int chrysanthemums, roses, tulips;
- cin >> chrysanthemums >> roses >> tulips;
- string season, holiday;
- cin >> season >> holiday;
- double chrysanthemumPrice = season == "Spring" || season == "Summer" ? 2.00 : 3.75;
- double rosePrice = season == "Spring" || season == "Summer" ? 4.10 : 4.50;
- double tulipPrice = season == "Spring" || season == "Summer" ? 2.50 : 4.15;
- double totalSum = (chrysanthemums * chrysanthemumPrice + roses * rosePrice + tulips * tulipPrice) * (holiday == "Y" ? 1.15 : 1);
- totalSum *= tulips > 7 && season == "Spring" ? 0.95 : roses >= 10 && season == "Winter" ? 0.90 : 1;
- totalSum *= chrysanthemums + roses + tulips > 20 ? 0.80 : 1;
- printf("%.2f\n", totalSum + 2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement