radidim

Problem 3. Heart Delivery

May 11th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. namespace CSharp_Shell
  7. {
  8.  
  9.     public static class Program
  10.     {
  11.         public static void Main()
  12.         {
  13.            var line = Console.ReadLine()
  14.            .Split(new[]{'@',' '}, StringSplitOptions.RemoveEmptyEntries)
  15.            .Select(int.Parse)
  16.            .ToArray();
  17.            
  18.            var s = 0;
  19.            var houseCount = 0;
  20.            
  21.            while(true)
  22.            {
  23.             var line1 = Console.ReadLine().ToLower();
  24.             if(line1=="love!")
  25.             {
  26.                 break;
  27.             }
  28.            
  29.             var input = line1.Split(' ');
  30.             var command = input[0].ToLower();
  31.             var jump = int.Parse(input[1]);
  32.             if (command == "jump")
  33.             {
  34.      
  35.            
  36.             for(int i = 0;i<line.Length;i++)
  37.             {
  38.                 if(s+jump>line.Length-1)
  39.                 {
  40.                    
  41.                     s = 0;
  42.                    
  43.            
  44.                     if(line[s]>0)
  45.                     {
  46.                         line[s]-=2;
  47.                         if(line[s]==0)
  48.                         {
  49.                             Console.WriteLine($"Place {s} has Valentine's day.");
  50.                             houseCount++;
  51.                         }
  52.          
  53.                         break;
  54.                     }
  55.                     else if(line[s]>=0)
  56.                     {
  57.                         Console.WriteLine($"Place {s} already had Valentine's day.");
  58.                         break;
  59.                     }
  60.                    
  61.                 }
  62.                
  63.                 if(s+jump < line.Length)
  64.                 {
  65.                     s+=jump;
  66.                    
  67.                    
  68.                     if(line[s]>0)
  69.                     {
  70.                         line[s]-=2;
  71.                         if(line[s]==0)
  72.                         {
  73.                             Console.WriteLine($"Place {s} has Valentine's day.");
  74.                             houseCount++;
  75.                         }
  76.          
  77.                         break;
  78.                     }
  79.                     else if(line[s]>=0)
  80.                     {
  81.                         Console.WriteLine($"Place {s} already had Valentine's day.");
  82.                         break;
  83.                     }
  84.                    
  85.                 }  
  86.                 }
  87.                
  88.                
  89.                
  90.             }
  91.            
  92.            }
  93.            
  94.            Console.WriteLine($"Cupid's last position was {s}.");
  95.            if(houseCount==line.Length)
  96.            {
  97.             Console.WriteLine("Mission was successful.");
  98.            }
  99.            else
  100.            {
  101.             Console.WriteLine($"Cupid has failed {line.Length-houseCount} places.");
  102.            }
  103.            
  104.            
  105.         }
  106.     }
  107. }
Add Comment
Please, Sign In to add comment