Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string town, pack, vip;
- cin >> town >> pack >> vip;
- int days;
- cin >> days;
- if (days > 7) {
- days--;
- }
- double dayPrice = 0;
- if (town == "Bansko" || town == "Borovets") {
- if (pack == "withEquipment") {
- dayPrice = 100;
- if (vip == "yes") {
- dayPrice *= 0.90;
- }
- }
- else if (pack == "noEquipment") {
- dayPrice = 80;
- if (vip == "yes") {
- dayPrice *= 0.95;
- }
- }
- }
- else if (town == "Varna" || town == "Burgas") {
- if (pack == "withBreakfast") {
- dayPrice = 130;
- if (vip == "yes") {
- dayPrice *= 0.88;
- }
- }
- else if (pack == "noBreakfast") {
- dayPrice = 100;
- if (vip == "yes") {
- dayPrice *= 0.93;
- }
- }
- }
- if (days < 1) {
- cout << "Days must be positive number!\n";
- }
- else if (dayPrice > 0) {
- printf("The price is %.2flv! Have a nice time!", dayPrice * days);
- }
- else {
- cout << "Invalid input!\n";
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string town, pack, vip;
- cin >> town >> pack >> vip;
- int days;
- cin >> days;
- if (days > 7) {
- days--;
- }
- double dayPrice =
- town == "Bansko" || town == "Borovets" ?
- (pack == "withEquipment" ? 100 * (vip == "yes" ? 0.90 : 1) : pack == "noEquipment" ? 80 * (vip == "yes" ? 0.95 : 1) : 0) :
- town == "Varna" || town == "Burgas" ?
- (pack == "withBreakfast" ? 130 * (vip == "yes" ? 0.88 : 1) : pack == "noBreakfast" ? 100 * (vip == "yes" ? 0.93 : 1) : 0) : 0;
- days < 1 ? printf("Days must be positive number!\n") :
- dayPrice > 0 ? printf("The price is %.2flv! Have a nice time!", dayPrice * days) :
- printf("Invalid input!\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement