Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SantasHoliday
- {
- class Program
- {
- static void Main(string[] args)
- {
- int days = int.Parse(Console.ReadLine()) - 1;
- string type = Console.ReadLine();
- string rating = Console.ReadLine();
- double price = 0;
- if (days > 0)
- {
- if (type == "room for one person")
- {
- price = 18;
- }
- else if (type == "apartment")
- {
- price = 25;
- if (days < 10)
- {
- price *= 0.7;
- }
- else if (days > 15)
- {
- price *= 0.5;
- }
- else
- {
- price *= 0.65;
- }
- }
- else if (type == "president apartment")
- {
- price = 35;
- if (days < 10)
- {
- price *= 0.9;
- }
- else if (days > 15)
- {
- price *= 0.8;
- }
- else
- {
- price *= 0.85;
- }
- }
- if (rating == "positive")
- {
- price *= 1.25;
- }
- else
- {
- price *= 0.9;
- }
- price *= days;
- }
- Console.WriteLine($"{price:f2}");
- }
- }
- }
- РЕШЕНИЕ С IF И ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace SantasHoliday
- {
- class Program
- {
- static void Main(string[] args)
- {
- int days = int.Parse(Console.ReadLine()) - 1;
- string type = Console.ReadLine();
- string rating = Console.ReadLine();
- double price = 0;
- if (days > 0)
- {
- price = type == "room for one person" ? 18 : type == "apartment" ? 25 : 35;
- if (days < 10)
- {
- price *= type == "apartment" ? 0.7 : type == "president apartment" ? 0.9 : 1;
- }
- else if (days > 15)
- {
- price *= type == "apartment" ? 0.5 : type == "president apartment" ? 0.8 : 1;
- }
- else
- {
- price *= type == "apartment" ? 0.65 : type == "president apartment" ? 0.85 : 1;
- }
- price *= days * (rating == "positive" ? 1.25 : 0.9);
- }
- Console.WriteLine($"{price:f2}");
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace SantasHoliday
- {
- class Program
- {
- static void Main(string[] args)
- {
- int days = int.Parse(Console.ReadLine()) - 1;
- string type = Console.ReadLine();
- string rating = Console.ReadLine();
- double price = days > 0 ? ((type == "room for one person" ? 18 : type == "apartment" ? 25 : 35)
- * (days < 10 ? (type == "apartment" ? 0.7 : type == "president apartment" ? 0.9 : 1)
- : days > 15 ? (type == "apartment" ? 0.5 : type == "president apartment" ? 0.8 : 1)
- : (type == "apartment" ? 0.65 : type == "president apartment" ? 0.85 : 1))
- * (rating == "positive" ? 1.25 : 0.9) * days) : 0;
- Console.WriteLine($"{price:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement