Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _03PresentDelivery
- {
- class Program
- {
- static void Main(string[] args)
- {
- string initialHouses = Console.ReadLine();
- List<int> houses = initialHouses.Split('@').Select(int.Parse).ToList();
- int totalHouses = houses.Count;
- int totalIndexes = houses.Count - 1;
- int housesToDeliver = houses.Count;
- int finalIndex = 0;
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Merry Xmas!")
- {
- break;
- }
- string[] tokens = command.Split();
- string action = tokens[0];
- if (action == "Jump")
- {
- int jumpLen = int.Parse(tokens[1]);
- finalIndex += jumpLen;
- if (finalIndex>totalIndexes)
- {
- finalIndex = finalIndex % totalHouses;
- }
- houses[finalIndex] -= 2;
- if (houses[finalIndex]==0)
- {
- housesToDeliver--;
- }
- if (houses[finalIndex]<0 && houses[finalIndex]>=-2)
- {
- Console.WriteLine($"House {finalIndex} will have a Merry Christmas.");
- continue;
- }
- }
- }
- Console.WriteLine($"Santa's last position was {finalIndex}.");
- if (houses.Sum()<=0)
- {
- Console.WriteLine("Mission was successful.");
- }
- else
- {
- Console.WriteLine($"Santa has failed {housesToDeliver} houses.");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment