Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ СЪС SWITCH:
- using System;
- namespace Darts
- {
- class Program
- {
- static void Main(string[] args)
- {
- string name = Console.ReadLine();
- string zone = Console.ReadLine();
- int countYes = 0;
- int countNo = 0;
- int total = 301;
- while (zone != "Retire")
- {
- int dots = int.Parse(Console.ReadLine());
- switch (zone)
- {
- case "Double":
- dots *= 2;
- break;
- case "Triple":
- dots *= 3;
- break;
- }
- if (total < dots)
- {
- countNo++;
- }
- else
- {
- total -= dots;
- countYes++;
- }
- if (total == 0)
- {
- break;
- }
- zone = Console.ReadLine();
- }
- if (total == 0)
- {
- Console.WriteLine($"{name} won the leg with {countYes} shots.");
- }
- else
- {
- Console.WriteLine($"{name} retired after {countNo} unsuccessful shots.");
- }
- }
- }
- }
- РЕШЕНИЕ С IF-ELSE:
- using System;
- namespace Darts
- {
- class Program
- {
- static void Main(string[] args)
- {
- string name = Console.ReadLine();
- string zone = Console.ReadLine();
- int countYes = 0;
- int countNo = 0;
- int total = 301;
- while (zone != "Retire")
- {
- int dots = int.Parse(Console.ReadLine());
- if (zone == "Double")
- {
- dots *= 2;
- }
- else if (zone == "Triple")
- {
- dots *= 3;
- }
- if (total < dots)
- {
- countNo++;
- }
- else
- {
- total -= dots;
- countYes++;
- }
- if (total == 0)
- {
- break;
- }
- zone = Console.ReadLine();
- }
- if (total == 0)
- {
- Console.WriteLine($"{name} won the leg with {countYes} shots.");
- }
- else
- {
- Console.WriteLine($"{name} retired after {countNo} unsuccessful shots.");
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace Darts
- {
- class Program
- {
- static void Main(string[] args)
- {
- string name = Console.ReadLine();
- string zone = Console.ReadLine();
- int countYes = 0;
- int countNo = 0;
- int total = 301;
- while (zone != "Retire")
- {
- int dots = int.Parse(Console.ReadLine()) * (zone == "Double" ? 2 : zone == "Triple" ? 3 : 1);
- _ = total < dots ? countNo++ : countYes++;
- total -= total >= dots ? dots : 0;
- if (total == 0)
- {
- break;
- }
- zone = Console.ReadLine();
- }
- Console.WriteLine(total == 0 ? $"{name} won the leg with {countYes} shots."
- : $"{name} retired after {countNo} unsuccessful shots.");
- }
- }
- }
Add Comment
Please, Sign In to add comment