silvana1303

heart delivery

Jun 28th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5. using System.Threading;
  6.  
  7. namespace exampreparation
  8. {
  9.     class exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> houses = Console.ReadLine().Split("@").Select(int.Parse).ToList();
  14.  
  15.             string[] command = Console.ReadLine().Split().ToArray();
  16.  
  17.             int currentIndex = 0;
  18.             int position = 0;
  19.  
  20.             while (command[0] != "Love!")
  21.             {
  22.                 int length = int.Parse(command[1]);
  23.  
  24.                 position = currentIndex + length;
  25.  
  26.                 if (position > houses.Count)
  27.                 {
  28.                     position = 0;
  29.                 }
  30.  
  31.                 if (position >= 0 && position < houses.Count && houses[position] > 0)
  32.                 {
  33.                     houses[position] -= 2;
  34.  
  35.                     if (houses[position] == 0)
  36.                     {
  37.                         Console.WriteLine($"Place {position} has Valentine's day.");
  38.                     }
  39.                 }
  40.                 else if (position >= 0 && position < houses.Count && houses[position] == 0)
  41.                 {
  42.                     Console.WriteLine($"Place {position} already had Valentine's day.");
  43.                 }
  44.                 currentIndex = position;
  45.  
  46.                 command = Console.ReadLine().Split().ToArray();
  47.             }
  48.  
  49.             Console.WriteLine($"Cupid's last position was {position}.");
  50.  
  51.             if (houses.Sum() == 0)
  52.             {
  53.                 Console.WriteLine("Mission was successful.");
  54.             }
  55.             else
  56.             {
  57.                 int count = 0;
  58.                 foreach (var item in houses)
  59.                 {
  60.                    
  61.                     if (item != 0)
  62.                     {
  63.                         count++;
  64.                     }
  65.                 }
  66.                 Console.WriteLine($"Cupid has failed {count} places.");
  67.             }
  68.         }
  69.  
  70.     }
  71. }
Add Comment
Please, Sign In to add comment