Advertisement
Spocoman

03. Heart Delivery

Nov 9th, 2023
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace HeartDelivery
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var houses = Console.ReadLine().Split('@').Select(int.Parse).ToList();
  10.  
  11.             int index = 0;
  12.             string command;
  13.  
  14.             while ((command = Console.ReadLine()) != "Love!")
  15.             {
  16.                 index += int.Parse(command.Substring(5));
  17.                 if (index >= houses.Count)
  18.                 {
  19.                     index = 0;
  20.                 }
  21.  
  22.                 if (houses[index] == 0)
  23.                 {
  24.                     Console.WriteLine($"Place {index} already had Valentine's day.");
  25.                 }
  26.                 else
  27.                 {
  28.                     houses[index] -= 2;
  29.                     if (houses[index] == 0)
  30.                     {
  31.                         Console.WriteLine($"Place {index} has Valentine's day.");
  32.                     }
  33.                 }
  34.             }
  35.  
  36.             Console.WriteLine($"Cupid's last position was {index}.");
  37.             int houseCount = houses.Where(x => x > 0).Count();
  38.             Console.WriteLine(houseCount == 0 ? "Mission was successful." : $"Cupid has failed {houseCount} places.");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement