Advertisement
Kristina_Ivanova

Untitled

Mar 5th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Lists06_Present_delivery
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             List<int> houses = Console.ReadLine()
  12.                 .Split("@")
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.             int indexStartHouse = 0;
  16.             string command = Console.ReadLine();
  17.             int lastPosition = 0;
  18.             while (command != "Merry Xmas!")
  19.             {
  20.                 string[] tokens = command.Split().ToArray();
  21.                 int jump = int.Parse(tokens[1]);
  22.  
  23.  
  24.                 int indexCurrentHouse = indexStartHouse + jump;
  25.                 indexStartHouse = indexCurrentHouse;
  26.  
  27.                 if (indexCurrentHouse > houses.Count - 1)
  28.                 {
  29.                     indexCurrentHouse = indexCurrentHouse % houses.Count;
  30.                     indexStartHouse = indexCurrentHouse;
  31.                 }
  32.  
  33.                 if (houses[indexCurrentHouse] == 0)
  34.                 {
  35.                     Console.WriteLine($"House {indexCurrentHouse} will have a Merry Christmas.");
  36.                 }
  37.                 else if (houses[indexCurrentHouse] > 0)
  38.                 {
  39.                     houses[indexCurrentHouse] -= 2;
  40.                 }
  41.  
  42.                 lastPosition = indexCurrentHouse;
  43.                 command = Console.ReadLine();
  44.             }
  45.  
  46.             Console.WriteLine($"Santa's last position was {lastPosition}.");
  47.  
  48.             if (houses.Sum() == 0)
  49.             {
  50.                 Console.WriteLine($"Mission was successful.");
  51.             }
  52.             else
  53.             {
  54.                 houses.RemoveAll(x => x == 0);
  55.                 Console.WriteLine($"Santa has failed {houses.Count} houses.");
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement