Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ С IF-ELSE:
- using System;
- namespace HotelRoom
- {
- class Program
- {
- static void Main(string[] args)
- {
- string month = Console.ReadLine();
- int night = int.Parse(Console.ReadLine());
- double apartment = night;
- double studio = night;
- if (month == "May" || month == "October")
- {
- apartment *= 65;
- studio *= 50;
- if (night > 7 && night <= 14)
- {
- studio *= 0.95;
- }
- else if (night > 14)
- {
- studio *= 0.7;
- }
- }
- else if (month == "June" || month == "September")
- {
- apartment *= 68.7;
- studio *= 75.2;
- if (night > 14)
- {
- studio *= 0.8;
- }
- }
- else if (month == "July" || month == "August")
- {
- apartment *= 77;
- studio *= 76;
- }
- if (night > 14)
- {
- apartment *= 0.9;
- }
- Console.WriteLine($"Apartment: {apartment:F2} lv.");
- Console.WriteLine($"Studio: {studio:F2} lv.");
- }
- }
- }
- РЕШЕНИЕ С IF-ELSE И ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace HotelRoom
- {
- class Program
- {
- static void Main(string[] args)
- {
- string month = Console.ReadLine();
- int night = int.Parse(Console.ReadLine());
- double apartment = night;
- double studio = night;
- if (month == "May" || month == "October")
- {
- apartment *= 65;
- studio *= 50 * (night > 7 && night <= 14 ? 0.95 : night > 14 ? 0.7 : 1);
- }
- else if (month == "June" || month == "September")
- {
- apartment *= 68.7;
- studio *= 75.2 * (night > 14 ? 0.8 : 1);
- }
- else if (month == "July" || month == "August")
- {
- apartment *= 77;
- studio *= 76;
- }
- apartment *= night > 14 ? 0.9 : 1;
- Console.WriteLine($"Apartment: {apartment:F2} lv.");
- Console.WriteLine($"Studio: {studio:F2} lv.");
- }
- }
- }
- РЕШЕНИЕ СЪС SWITCH:
- using System;
- namespace HotelRoom
- {
- class Program
- {
- static void Main(string[] args)
- {
- string month = Console.ReadLine();
- int night = int.Parse(Console.ReadLine());
- double apartment = night;
- double studio = night;
- switch (month)
- {
- case "May":
- case "October":
- apartment *= 65;
- studio *= 50;
- if (night > 7 && night <= 14)
- {
- studio *= 0.95;
- }
- else if (night > 14)
- {
- studio *= 0.7;
- }
- break;
- case "June":
- case "September":
- apartment *= 68.7;
- studio *= 75.2;
- if (night > 14)
- {
- studio *= 0.8;
- }
- break;
- case "July":
- case "August":
- apartment *= 77;
- studio *= 76;
- break;
- }
- if (night > 14)
- {
- apartment *= 0.9;
- }
- Console.WriteLine($"Apartment: {apartment:F2} lv.");
- Console.WriteLine($"Studio: {studio:F2} lv.");
- }
- }
- }
- РЕШЕНИЕ СЪС SWITCH И ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace HotelRoom
- {
- class Program
- {
- static void Main(string[] args)
- {
- string month = Console.ReadLine();
- int night = int.Parse(Console.ReadLine());
- double apartment = night;
- double studio = night;
- switch (month)
- {
- case "May":
- case "October":
- apartment *= 65;
- studio *= 50 * (night > 7 && night <= 14 ? 0.95 : night > 14 ? 0.7 : 1);
- break;
- case "June":
- case "September":
- apartment *= 68.7;
- studio *= 75.2 * (night > 14 ? 0.8 : 1);
- break;
- case "July":
- case "August":
- apartment *= 77;
- studio *= 76;
- break;
- }
- apartment *= night > 14 ? 0.9 : 1;
- Console.WriteLine($"Apartment: {apartment:F2} lv.");
- Console.WriteLine($"Studio: {studio:F2} lv.");
- }
- }
- }
- РЕШЕНИЕ САМО С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace HotelRoom
- {
- class Program
- {
- static void Main(string[] args)
- {
- string month = Console.ReadLine();
- int night = int.Parse(Console.ReadLine());
- double apartment = night * (month == "May" || month == "October" ? 65 : month == "June" || month == "September" ? 68.7 : 77) * (night > 14 ? 0.9 : 1);
- double studio = night * (month == "May" || month == "October" ? 50 * (night > 7 && night <= 14 ? 0.95 : night > 14 ? 0.7 : 1) :
- month == "June" || month == "September" ? 75.2* (night > 14 ? 0.8 : 1) : 76);
- Console.WriteLine($"Apartment: {apartment:F2} lv.");
- Console.WriteLine($"Studio: {studio:F2} lv.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement