Daniel_007

03. Heart Delivery

Feb 29th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace MidExam_03
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> neighborhood = Console.ReadLine().Split("@").Select(int.Parse).ToList();
  12.             int possition = 0;
  13.             while (true)
  14.             {
  15.                 string[] command = Console.ReadLine().Split(" ").ToArray();
  16.                 if (command[0] == "Jump")
  17.                 {
  18.                    possition= jump(neighborhood, command[1], possition);
  19.                 }
  20.                 else if (command[0]=="Love!")
  21.                 {
  22.                     love(neighborhood, possition);
  23.                     return;
  24.                 }
  25.             }
  26.         }
  27.  
  28.         private static void love(List<int> neighborhood, int possition)
  29.         {
  30.             int checker = 0;
  31.             for (int i = 0; i < neighborhood.Count; i++)
  32.             {
  33.  
  34.                 if (neighborhood[i]==0)
  35.                 {
  36.                     checker++;
  37.                 }
  38.             }
  39.             if (checker == neighborhood.Count)
  40.             {
  41.                 Console.WriteLine($"Cupid's last position was {possition}.");
  42.                 Console.WriteLine("Mission was successful.");
  43.             }
  44.             else
  45.             {
  46.                 Console.WriteLine($"Cupid's last position was {possition}.");
  47.                 Console.WriteLine($"Cupid has failed {neighborhood.Count-checker} places.");
  48.             }
  49.         }
  50.  
  51.         private static int jump(List<int> neighborhood, string lenght, int possition)
  52.         {
  53.             int index = int.Parse(lenght);
  54.             if (index>=neighborhood.Count || (possition+index)>=neighborhood.Count)
  55.             {
  56.                 if (neighborhood[0] == 0)
  57.                 {
  58.                     Console.WriteLine("Place 0 already had Valentine's day.");
  59.                 }
  60.                 else
  61.                 {
  62.                     neighborhood[0] = neighborhood[0] - 2;
  63.                     if (neighborhood[0] <= 0)
  64.                     {
  65.                         neighborhood[0] = 0;
  66.                         Console.WriteLine("Place 0 has Valentine's day.");
  67.                     }
  68.                 }
  69.                 return 0;
  70.             }
  71.             possition += index;
  72.             if (neighborhood[possition] == 0)
  73.             {
  74.                 Console.WriteLine($"Place {possition} already had Valentine's day.");
  75.             }
  76.             else
  77.             {
  78.                 neighborhood[possition] = neighborhood[possition] - 2;
  79.                 if (neighborhood[possition] <= 0)
  80.                 {
  81.                     neighborhood[possition] = 0;
  82.                     Console.WriteLine($"Place {possition} has Valentine's day.");
  83.                 }
  84.             }
  85.             return possition;  
  86.         }
  87.     }
  88. }
Add Comment
Please, Sign In to add comment