Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int juniors, seniors;
- cin >> juniors >> seniors;
- string trace;
- cin >> trace;
- double juniorPrice;
- double seniorPrice;
- if (trace == "trail") {
- juniorPrice = 5.5;
- seniorPrice = 7;
- }
- else if (trace == "cross-country") {
- juniorPrice = 8;
- seniorPrice = 9.5;
- }
- else if (trace == "downhill") {
- juniorPrice = 12.25;
- seniorPrice = 13.75;
- }
- else if (trace == "road") {
- juniorPrice = 20;
- seniorPrice = 21.5;
- }
- double totalSum = juniors * juniorPrice + seniors * seniorPrice;
- if (juniors + seniors >= 50 && trace == "cross-country") {
- totalSum *= 0.75;
- }
- totalSum *= 0.95;
- printf("%.2f\n", totalSum);
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int juniors, seniors;
- cin >> juniors >> seniors;
- string trace;
- cin >> trace;
- double juniorPrice =
- trace == "trail" ? 5.50 :
- trace == "cross-country" ? 8.00 :
- trace == "downhill" ? 12.25 : 20;
- double seniorPrice =
- trace == "trail" ? 7.00 :
- trace == "cross-country" ? 9.50 :
- trace == "downhill" ? 13.75 : 21.50;
- double totalSum = (juniors * juniorPrice + seniors * seniorPrice)
- * (juniors + seniors >= 50 && trace == "cross-country" ? 0.75 : 1) * 0.95;
- printf("%.2f\n", totalSum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement