Advertisement
Guest User

Untitled

a guest
Jul 4th, 2019
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Problem
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             var list = Console.ReadLine()
  13.                 .Split(' ')
  14.                 .Where(x => !string.IsNullOrWhiteSpace(x))
  15.                 .ToList();
  16.             var print = new List<string>();
  17.  
  18.             string input;
  19.  
  20.             while (!(input = Console.ReadLine()).Contains("Print"))
  21.             {
  22.                 string command = input.Split(" ")[0];
  23.  
  24.                 if (command == "Join")
  25.                 {
  26.                     string name = input.Split(" ")[1];
  27.                  
  28.                     if (!list.Contains(name))
  29.                     {
  30.                         list.Add(name);
  31.                     }
  32.                 }
  33.                 else if (command == "Jump")
  34.                 {
  35.                     string name = input.Split(" ")[1];
  36.                     int index = int.Parse(input.Split(" ")[2]);
  37.  
  38.                     if (index >= 0 && index < list.Count)
  39.                     {
  40.                         list.Insert(index, name);
  41.                     }
  42.                 }
  43.                 else if (command == "Dive")
  44.                 {
  45.                     int index = int.Parse(input.Split(" ")[1]);
  46.  
  47.                     if (index >= 0 && index < list.Count)
  48.                     {
  49.                         list.RemoveAt(index);
  50.                     }
  51.                 }
  52.                 else if (command == "First")
  53.                 {
  54.                     int count = int.Parse(input.Split(" ")[1]);
  55.  
  56.                         if (count >= list.Count)
  57.                         {
  58.                             count = list.Count;
  59.                         }
  60.                         print = list.Take(count).Select(x => x).ToList();
  61.                         //print.Reverse();
  62.                         Console.WriteLine(string.Join(" ", print));
  63.                 }
  64.                 else if (command == "Last")
  65.                 {
  66.                     int count = int.Parse(input.Split(" ")[1]);
  67.  
  68.                     if (count >= list.Count)
  69.                     {
  70.                         count = list.Count;
  71.                     }
  72.                     list.Reverse();
  73.                     print = list.Take(count).Select(x => x).ToList();
  74.                     print.Reverse();
  75.                     list.Reverse();
  76.                     Console.WriteLine(string.Join(" ", print));
  77.                 }
  78.  
  79.             }
  80.             if (input.Split(" ")[1] == "Reversed")
  81.             {
  82.                 list.Reverse();
  83.             }
  84.             Console.WriteLine($"Frogs: {string.Join(" ", list)}");
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement