Advertisement
DeeAG

03.HeartDelivery

Feb 24th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.HeartDelivery
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> needHearts = Console.ReadLine()
  12.                 .Split('@', StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.  
  16.             int currentPosition = 0;
  17.  
  18.             while (true)
  19.             {
  20.                 string input = Console.ReadLine();
  21.  
  22.                 if (input == "Love!")
  23.                 {
  24.                     break;
  25.                 }
  26.  
  27.                 string[] tokens = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  28.  
  29.                 int jumpLength = int.Parse(tokens[1]);
  30.  
  31.                 currentPosition += jumpLength;
  32.  
  33.                 if (currentPosition > needHearts.Count - 1)
  34.                 {
  35.                     currentPosition = 0;
  36.                 }
  37.  
  38.                 if (needHearts[currentPosition] == 0)
  39.                 {
  40.                     Console.WriteLine($"Place {currentPosition} already had Valentine's day.");
  41.                 }
  42.                 else
  43.                 {
  44.                     needHearts[currentPosition] -= 2;
  45.  
  46.                     if (needHearts[currentPosition] == 0)
  47.                     {
  48.                         Console.WriteLine($"Place {currentPosition} has Valentine's day.");
  49.                     }
  50.                 }
  51.             }
  52.  
  53.             Console.WriteLine($"Cupid's last position was {currentPosition}.");
  54.  
  55.             if (needHearts.Sum() == 0)
  56.             {
  57.                 Console.WriteLine("Mission was successful.");
  58.             }
  59.             else
  60.             {
  61.                 Console.WriteLine($"Cupid has failed {needHearts.Count(h => h > 0)} places.");
  62.             }
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement