Advertisement
knoteva

Untitled

Aug 5th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Problem
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var list = Console.ReadLine()
  12.                 .Split()
  13.                 .ToList();
  14.             string input = Console.ReadLine();
  15.             while (true)
  16.             {
  17.                 string[] tokens = input.Split();
  18.                 string command = tokens[0];
  19.                 if (command == "Join")
  20.                 {
  21.                     string name = tokens[1];
  22.                     if (!list.Contains(name))
  23.                     {
  24.                         list.Add(name);
  25.                     }
  26.                 }
  27.                 else if (command == "Jump")
  28.                 {
  29.                     string name = tokens[1];
  30.                     int index = int.Parse(tokens[2]);
  31.                     if (index >= 0 && index < list.Count)
  32.                     {
  33.                         list.Insert(index, name);
  34.                     }
  35.                 }
  36.                 else if (command == "Dive")
  37.                 {
  38.                     int index = int.Parse(tokens[1]);
  39.                     if (index >= 0 && index < list.Count)
  40.                     {
  41.                         list.RemoveAt(index);
  42.                     }
  43.                 }
  44.  
  45.                 else if (command == "First")
  46.                 {
  47.                     int count = int.Parse(tokens[1]);
  48.                     int lastIndex = count;
  49.  
  50.                     if (lastIndex > list.Count)
  51.                     {
  52.                         lastIndex = list.Count;
  53.                     }
  54.                     for (int i = 0; i < lastIndex; i++)
  55.                     {
  56.                         Console.Write(list[i] + " "); // Трябва да се принтират на един ред
  57.                     }
  58.                     //Console.WriteLine(); // Принтираме празен ред
  59.                 }
  60.                 else if (command == "Last") // Ако не обърнеш листа няма как да принтираш от последния символ, защото се иска при "A B C Q D E F G" и Last 3 да се принтира "E F G", а не "G F D"
  61.                 {
  62.                     int count = int.Parse(tokens[1]);
  63.                     int firstIndex = list.Count - count;
  64.  
  65.                     if (firstIndex < 0)
  66.                     {
  67.                         firstIndex = 0;
  68.                     }
  69.                     for (int i = firstIndex; i < list.Count; i++)
  70.                     {
  71.                         Console.Write(list[i] + " "); // Трябва да се принтират на един ред
  72.                     }
  73.                     Console.WriteLine(); // Принтираме празен ред
  74.                 }
  75.  
  76.                 else if (command == "Print")
  77.                 {
  78.                     string normalOrReversed = tokens[1];
  79.                     if (normalOrReversed == "Normal")
  80.                     {
  81.                         Console.WriteLine("Frogs: " + string.Join(" ", list)); // Трябва да има празно след :
  82.                         break;
  83.                     }
  84.                     else if (normalOrReversed == "Reversed")
  85.                     {
  86.                         list.Reverse();
  87.                         Console.WriteLine("Frogs: " + string.Join(" ", list)); // Трябва да има празно след :
  88.                         break;
  89.                     }
  90.                 }
  91.                 input = Console.ReadLine();
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement