Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- string season, group;
- cin >> season >> group;
- int people, nights;
- cin >> people >> nights;
- double pricePerNight;
- string sport;
- if (season == "Winter") {
- if (group == "boys") {
- pricePerNight = 9.60;
- sport = "Judo";
- }
- else if (group == "girls") {
- pricePerNight = 9.60;
- sport = "Gymnastics";
- }
- else if (group == "mixed") {
- pricePerNight = 10;
- sport = "Ski";
- }
- }
- else if (season == "Spring") {
- if (group == "boys") {
- pricePerNight = 7.20;
- sport = "Tennis";
- }
- else if (group == "girls") {
- pricePerNight = 7.20;
- sport = "Athletics";
- }
- else if (group == "mixed") {
- pricePerNight = 9.50;
- sport = "Cycling";
- }
- }
- else {
- if (group == "boys") {
- pricePerNight = 15;
- sport = "Football";
- }
- else if (group == "girls") {
- pricePerNight = 15;
- sport = "Volleyball";
- }
- else if (group == "mixed") {
- pricePerNight = 20;
- sport = "Swimming";
- }
- }
- if (people >= 10 && people < 20) {
- pricePerNight *= 0.95;
- }
- else if (people >= 20 && people < 50) {
- pricePerNight *= 0.85;
- }
- else if (people >= 50) {
- pricePerNight *= 0.50;
- }
- double totalSum = pricePerNight * nights * people;
- cout << sport << " " << fixed << setprecision(2) << totalSum << " lv." << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- string season, group;
- cin >> season >> group;
- int people, nights;
- cin >> people >> nights;
- double pricePerNight =
- season == "Winter" ? (group == "mixed" ? 10 : 9.60) :
- season == "Spring" ? (group == "mixed" ? 9.50 : 7.20) : (group == "mixed" ? 20 : 15);
- pricePerNight *=
- people >= 10 && people < 20 ? 0.95 :
- people >= 20 && people < 50 ? 0.85 :
- people >= 50 ? 0.50 : 1;
- string sport =
- season == "Winter" ? (group == "boys" ? "Judo" : group == "girls" ? "Gymnastics" : "Ski") :
- season == "Spring" ? (group == "boys" ? "Tennis" : group == "girls" ? "Athletics" : "Cycling") :
- (group == "boys" ? "Football" : group == "girls" ? "Volleyball" : "Swimming");
- double totalSum = pricePerNight * nights * people;
- cout << sport << " " << fixed << setprecision(2) << totalSum << " lv." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement