Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Lists06_Present_delivery
- {
- class Program
- {
- static void Main()
- {
- List<int> houses = Console.ReadLine()
- .Split("@")
- .Select(int.Parse)
- .ToList();
- int indexStartHouse = 0;
- string command = Console.ReadLine();
- int lastPosition = 0;
- while (command != "Merry Xmas!")
- {
- string[] tokens = command.Split().ToArray();
- int jump = int.Parse(tokens[1]);
- int indexCurrentHouse = indexStartHouse + jump;
- indexStartHouse = indexCurrentHouse;
- if (indexCurrentHouse > houses.Count - 1)
- {
- indexCurrentHouse = indexCurrentHouse % houses.Count;
- indexStartHouse = indexCurrentHouse;
- }
- if (houses[indexCurrentHouse] == 0)
- {
- Console.WriteLine($"House {indexCurrentHouse} will have a Merry Christmas.");
- }
- else if (houses[indexCurrentHouse] > 0)
- {
- houses[indexCurrentHouse] -= 2;
- }
- lastPosition = indexCurrentHouse;
- command = Console.ReadLine();
- }
- Console.WriteLine($"Santa's last position was {lastPosition}.");
- if (houses.Sum() == 0)
- {
- Console.WriteLine($"Mission was successful.");
- }
- else
- {
- houses.RemoveAll(x => x == 0);
- Console.WriteLine($"Santa has failed {houses.Count} houses.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement