Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace HeartDelivery
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<int> listOfHouses = Console.ReadLine().Split('@').Select(int.Parse).ToList();
- int currentHouse = 0;
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "Love!")
- {
- string[] commandArray = command.Split().ToArray();
- if (commandArray[0] == "Jump")
- {
- int jumpLength = int.Parse(commandArray[1]);
- if (currentHouse + jumpLength >= 0 && currentHouse + jumpLength <= listOfHouses.Count - 1 && listOfHouses[currentHouse + jumpLength] != 0)
- {
- listOfHouses[currentHouse + jumpLength] = listOfHouses[currentHouse + jumpLength] - 2;
- if (listOfHouses[currentHouse + jumpLength] == 0)
- {
- Console.WriteLine($"Place {currentHouse + jumpLength} has Valentine's day.");
- }
- currentHouse += jumpLength;
- }
- else if (currentHouse + jumpLength >= 0 && currentHouse + jumpLength <= listOfHouses.Count - 1 && listOfHouses[currentHouse + jumpLength] == 0)
- {
- Console.WriteLine($"Place {currentHouse + jumpLength} already had Valentine's day.");
- currentHouse += jumpLength;
- }
- else if (currentHouse + jumpLength > listOfHouses.Count - 1)
- {
- jumpLength = 0;
- currentHouse = 0;
- if (listOfHouses[jumpLength] == 0)
- {
- Console.WriteLine($"Place {jumpLength} already had Valentine's day.");
- }
- else
- {
- listOfHouses[jumpLength] = listOfHouses[jumpLength] - 2;
- if (listOfHouses[jumpLength] == 0)
- {
- Console.WriteLine($"Place {jumpLength} has Valentine's day.");
- }
- currentHouse += jumpLength;
- }
- }
- }
- }
- Console.WriteLine($"Cupid's last position was {currentHouse}.");
- if (listOfHouses.Sum() == 0)
- {
- Console.WriteLine($"Mission was successful.");
- }
- else
- {
- int countHouseWithoutValentinsDay = 0;
- for (int i = 0; i < listOfHouses.Count; i++)
- {
- if (listOfHouses[i] > 0)
- countHouseWithoutValentinsDay++;
- }
- Console.WriteLine($"Cupid has failed {countHouseWithoutValentinsDay} places.");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment