VasilKotsev

03.Presents Delivery - C#

Jan 19th, 2019
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. namespace PresentDelivery
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class EntryPoint
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<int> houses = Console.ReadLine()
  12.                 .Split(new[] { '@' }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(x => int.Parse(x))
  14.                 .ToList();
  15.  
  16.             int santaIndex = 0;
  17.  
  18.             while (true)
  19.             {
  20.                 string inputArgs = Console.ReadLine();
  21.  
  22.                 if (inputArgs == "Merry Xmas!")
  23.                 {
  24.                     break;
  25.                 }
  26.  
  27.                 string[] commandArgs = inputArgs
  28.                     .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  29.  
  30.                 if (commandArgs[0] == "Jump")
  31.                 {
  32.                     int timesToJump = int.Parse(commandArgs[1]);
  33.  
  34.                     if (santaIndex + timesToJump >= houses.Count)
  35.                     {
  36.                         // start from 0
  37.                         santaIndex = (santaIndex + timesToJump) % houses.Count;
  38.                     }
  39.  
  40.                     else
  41.                     {
  42.                         santaIndex += timesToJump;
  43.                     }
  44.  
  45.  
  46.  
  47.                     if (houses[santaIndex] == 0)
  48.                     {
  49.                         Console.WriteLine($"House {santaIndex} will have a Merry Christmas.");
  50.                     }
  51.  
  52.                     else
  53.                     {
  54.                         houses[santaIndex] -= 2;                    
  55.                     }
  56.                 }
  57.             }
  58.  
  59.             int failedHouses = houses.Where(x => x != 0).Count();
  60.  
  61.             Console.WriteLine($"Santa's last position was {santaIndex}.");
  62.  
  63.             if (failedHouses > 0)
  64.             {
  65.                 Console.WriteLine($"Santa has failed {failedHouses} houses.");
  66.             }
  67.  
  68.             else
  69.             {
  70.                 Console.WriteLine("Mission was successful.");
  71.             }
  72.         }
  73.     }
  74. }
Add Comment
Please, Sign In to add comment