Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MidExam_03
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> neighborhood = Console.ReadLine().Split("@").Select(int.Parse).ToList();
- int possition = 0;
- while (true)
- {
- string[] command = Console.ReadLine().Split(" ").ToArray();
- if (command[0] == "Jump")
- {
- possition= jump(neighborhood, command[1], possition);
- }
- else if (command[0]=="Love!")
- {
- love(neighborhood, possition);
- return;
- }
- }
- }
- private static void love(List<int> neighborhood, int possition)
- {
- int checker = 0;
- for (int i = 0; i < neighborhood.Count; i++)
- {
- if (neighborhood[i]==0)
- {
- checker++;
- }
- }
- if (checker == neighborhood.Count)
- {
- Console.WriteLine($"Cupid's last position was {possition}.");
- Console.WriteLine("Mission was successful.");
- }
- else
- {
- Console.WriteLine($"Cupid's last position was {possition}.");
- Console.WriteLine($"Cupid has failed {neighborhood.Count-checker} places.");
- }
- }
- private static int jump(List<int> neighborhood, string lenght, int possition)
- {
- int index = int.Parse(lenght);
- if (index>=neighborhood.Count || (possition+index)>=neighborhood.Count)
- {
- if (neighborhood[0] == 0)
- {
- Console.WriteLine("Place 0 already had Valentine's day.");
- }
- else
- {
- neighborhood[0] = neighborhood[0] - 2;
- if (neighborhood[0] <= 0)
- {
- neighborhood[0] = 0;
- Console.WriteLine("Place 0 has Valentine's day.");
- }
- }
- return 0;
- }
- possition += index;
- if (neighborhood[possition] == 0)
- {
- Console.WriteLine($"Place {possition} already had Valentine's day.");
- }
- else
- {
- neighborhood[possition] = neighborhood[possition] - 2;
- if (neighborhood[possition] <= 0)
- {
- neighborhood[possition] = 0;
- Console.WriteLine($"Place {possition} has Valentine's day.");
- }
- }
- return possition;
- }
- }
- }
Add Comment
Please, Sign In to add comment