Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int days;
- cin >> days;
- int nights = days - 1;
- string type, rating;
- cin >> type >> rating;
- double price = 0;
- if (nights > 0) {
- if (type == "room for one person") {
- price = 18.00;
- }
- else if (type == "apartment") {
- price = 25.00;
- if (nights < 10) {
- price *= 0.70;
- }
- else if (nights > 15) {
- price *= 0.50;
- }
- else {
- price *= 0.65;
- }
- }
- else {
- price = 35.00;
- if (nights < 10) {
- price *= 0.90;
- }
- else if (nights > 15) {
- price *= 0.80;
- }
- else {
- price *= 0.85;
- }
- }
- if (rating == "positive") {
- price *= 1.25;
- }
- else {
- price *= 0.90;
- }
- }
- printf("%.2f\n", price * nights);
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int days;
- cin >> days;
- int nights = days - 1;
- string type, rating;
- cin >> type >> rating;
- double price =
- nights > 0 ?
- ((type == "room for one person" ? 18.00 :
- type == "apartment" ? 25.00 * (nights < 10 ? 0.70 : nights > 15 ? 0.50 : 0.65) :
- 35.00 * (nights < 10 ? 0.90 : nights > 15 ? 0.80 : 0.85)) * (rating == "positive" ? 1.25 : 0.90)) : 0;
- printf("%.2f\n", price * nights);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement