ralichka

Exam-30.06.2019-03.FrogSquad

Oct 30th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.FroggySquad
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> frogs = Console.ReadLine().Split().ToList();
  12.  
  13.  
  14.             string[] command = Console.ReadLine().Split();
  15.             string word = command[0];
  16.  
  17.             while (word != "Print")
  18.             {
  19.  
  20.                 if (word == "Join")
  21.                 {
  22.                     string name = command[1];
  23.                     frogs.Add(name);
  24.                 }
  25.                 else if (word == "Jump")
  26.                 {
  27.                     string name = command[1];
  28.                     int index = int.Parse(command[2]);
  29.  
  30.                     if (index >= 0 && index < frogs.Count)
  31.                     {
  32.                         frogs.Insert(index, name);
  33.                     }
  34.                 }
  35.                 else if (word == "Dive")
  36.                 {
  37.                     int index = int.Parse(command[1]);
  38.  
  39.                     if (index >= 0 && index < frogs.Count)
  40.                     {
  41.                         frogs.RemoveAt(index);
  42.                     }
  43.                 }
  44.                 else if (word == "First")
  45.                 {
  46.                     int count = int.Parse(command[1]);
  47.  
  48.                     if (count > frogs.Count)
  49.                     {
  50.                         count = frogs.Count;
  51.                     }
  52.  
  53.  
  54.                     List<string> first = new List<string>();
  55.  
  56.                     for (int i = 0; i < count; i++)
  57.                     {
  58.                         first.Add(frogs[i]);
  59.                     }
  60.  
  61.                     Console.WriteLine(string.Join(" ", first));
  62.  
  63.                 }
  64.                 else if (word == "Last")
  65.                 {
  66.                     int count = int.Parse(command[1]);
  67.  
  68.                     if (count > frogs.Count)
  69.                     {
  70.                         count = frogs.Count;
  71.                     }
  72.  
  73.  
  74.                     List<string> last = new List<string>();
  75.                     List<string> copyFrogs = frogs.ToList();
  76.  
  77.                     for (int i = count; i > 0; i--)
  78.                     {
  79.                         last.Add(copyFrogs[copyFrogs.Count - 1]);
  80.                         copyFrogs.RemoveAt(copyFrogs.Count - 1);
  81.                     }
  82.                     last.Reverse();
  83.                     Console.WriteLine(string.Join(" ", last));
  84.  
  85.                 }
  86.                 command = Console.ReadLine().Split();
  87.                 word = command[0];
  88.  
  89.             }
  90.             if (word == "Print")
  91.             {
  92.                 if (command[1] == "Normal")
  93.                 {
  94.                     Console.WriteLine("Frogs: " + string.Join(" ", frogs));
  95.                 }
  96.                 else if (command[1] == "Reversed")
  97.                 {
  98.                     frogs.Reverse();
  99.                     Console.WriteLine("Frogs: " + string.Join(" ", frogs));
  100.                 }
  101.             }
  102.  
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment