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;
- cin.ignore();
- string room;
- getline(cin, room);
- string rating;
- getline(cin, rating);
- int nights = days - 1;
- double roomPrice = 18.00;
- double apartmentPrice = 25.00;
- double presidentApartmentPrice = 35.00;
- double totalSum;
- if (room == "room for one person") {
- totalSum = roomPrice * nights;
- }
- else if (room == "apartment") {
- totalSum = apartmentPrice * nights;
- if (nights < 10) {
- totalSum *= 0.70;
- }
- else if (nights >= 10 && nights < 15) {
- totalSum *= 0.65;
- }
- else if (nights >= 15) {
- totalSum *= 0.50;
- }
- }
- else {
- totalSum = presidentApartmentPrice * nights;
- if (nights < 10) {
- totalSum *= 0.90;
- }
- else if (nights >= 10 && nights < 15) {
- totalSum *= 0.85;
- }
- else if (nights >= 15) {
- totalSum *= 0.80;
- }
- }
- if (rating == "positive") {
- totalSum *= 1.25;
- }
- else {
- totalSum *= 0.90;
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << totalSum << endl;
- return 0;
- }
- Решение с тернарен оператор и printf():
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int days;
- cin >> days;
- cin.ignore();
- string room, rating;
- getline(cin, room);
- getline(cin, rating);
- int nights = days - 1;
- double roomPricePerNight = room == "room for one person" ? 18.00 : room == "apartment" ? 25.00 : 35.00;
- double totalSum = roomPricePerNight * nights;
- totalSum *=
- room == "apartment" ? (nights < 10 ? 0.70 : nights >= 15 ? 0.50 : 0.65) :
- room == "president apartment" ? (nights < 10 ? 0.90 : nights >= 15 ? 0.80 : 0.85) : 1;
- totalSum *= rating == "positive" ? 1.25 : 0.90;
- printf("%.2f\n", totalSum);
- return 0;
- }
- Тарикатско решение - Don't use at work! :)
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string days, room, rating;
- getline(cin, days);
- getline(cin, room);
- getline(cin, rating);
- int nights = stoi(days) - 1;
- printf("%.2f\n", ((room == "room for one person" ? 18.00 :
- room == "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))
- * nights * (rating == "positive" ? 1.25 : 0.90)));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement