Advertisement
silvana1303

frog squad

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