Advertisement
Spocoman

Santas Holiday

May 28th, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.76 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SantasHoliday
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int days = int.Parse(Console.ReadLine()) - 1;
  10.             string type = Console.ReadLine();
  11.             string rating = Console.ReadLine();
  12.             double price = 0;
  13.  
  14.             if (days > 0)
  15.             {
  16.                 if (type == "room for one person")
  17.                 {
  18.                     price = 18;
  19.                 }
  20.                 else if (type == "apartment")
  21.                 {
  22.                     price = 25;
  23.  
  24.                     if (days < 10)
  25.                     {
  26.                         price *= 0.7;
  27.                     }
  28.                     else if (days > 15)
  29.                     {
  30.                         price *= 0.5;
  31.                     }
  32.                     else
  33.                     {
  34.                         price *= 0.65;
  35.                     }
  36.                 }
  37.                 else if (type == "president apartment")
  38.                 {
  39.                     price = 35;
  40.  
  41.                     if (days < 10)
  42.                     {
  43.                         price *= 0.9;
  44.                     }
  45.                     else if (days > 15)
  46.                     {
  47.                         price *= 0.8;
  48.                     }
  49.                     else
  50.                     {
  51.                         price *= 0.85;
  52.                     }
  53.                 }
  54.  
  55.                 if (rating == "positive")
  56.                 {
  57.                     price *= 1.25;
  58.                 }
  59.                 else
  60.                 {
  61.                     price *= 0.9;
  62.                 }
  63.  
  64.                 price *= days;
  65.             }
  66.  
  67.             Console.WriteLine($"{price:f2}");
  68.         }
  69.     }
  70. }
  71.  
  72.  
  73. РЕШЕНИЕ С IF И ТЕРНАРЕН ОПЕРАТОР:
  74.  
  75. using System;
  76.  
  77. namespace SantasHoliday
  78. {
  79.     class Program
  80.     {
  81.         static void Main(string[] args)
  82.         {
  83.             int days = int.Parse(Console.ReadLine()) - 1;
  84.             string type = Console.ReadLine();
  85.             string rating = Console.ReadLine();
  86.             double price = 0;
  87.  
  88.             if (days > 0)
  89.             {
  90.                 price = type == "room for one person" ? 18 : type == "apartment" ? 25 : 35;
  91.  
  92.                 if (days < 10)
  93.                 {
  94.                     price *= type == "apartment" ? 0.7 : type == "president apartment" ? 0.9 : 1;
  95.                 }
  96.                 else if (days > 15)
  97.                 {
  98.                     price *= type == "apartment" ? 0.5 : type == "president apartment" ? 0.8 : 1;
  99.                 }
  100.                 else
  101.                 {
  102.                     price *= type == "apartment" ? 0.65 : type == "president apartment" ? 0.85 : 1;
  103.                 }
  104.  
  105.                 price *= days * (rating == "positive" ? 1.25 : 0.9);
  106.             }
  107.  
  108.             Console.WriteLine($"{price:f2}");
  109.         }
  110.     }
  111. }
  112.  
  113.  
  114. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  115.  
  116. using System;
  117.  
  118. namespace SantasHoliday
  119. {
  120.     class Program
  121.     {
  122.         static void Main(string[] args)
  123.         {
  124.             int days = int.Parse(Console.ReadLine()) - 1;
  125.             string type = Console.ReadLine();
  126.             string rating = Console.ReadLine();
  127.  
  128.             double price = days > 0 ? ((type == "room for one person" ? 18 : type == "apartment" ? 25 : 35)
  129.                          * (days < 10 ? (type == "apartment" ? 0.7 : type == "president apartment" ? 0.9 : 1)
  130.                          : days > 15 ? (type == "apartment" ? 0.5 : type == "president apartment" ? 0.8 : 1)
  131.                          : (type == "apartment" ? 0.65 : type == "president apartment" ? 0.85 : 1))
  132.                          * (rating == "positive" ? 1.25 : 0.9) * days) : 0;
  133.  
  134.             Console.WriteLine($"{price:f2}");
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement