Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02._Problem
- {
- class Program
- {
- static void Main(string[] args)
- {
- var list = Console.ReadLine()
- .Split()
- .ToList();
- string input = Console.ReadLine();
- while (true)
- {
- string[] tokens = input.Split();
- string command = tokens[0];
- if (command == "Join")
- {
- string name = tokens[1];
- if (!list.Contains(name))
- {
- list.Add(name);
- }
- }
- else if (command == "Jump")
- {
- string name = tokens[1];
- int index = int.Parse(tokens[2]);
- if (index >= 0 && index < list.Count)
- {
- list.Insert(index, name);
- }
- }
- else if (command == "Dive")
- {
- int index = int.Parse(tokens[1]);
- if (index >= 0 && index < list.Count)
- {
- list.RemoveAt(index);
- }
- }
- else if (command == "First")
- {
- int count = int.Parse(tokens[1]);
- int lastIndex = count;
- if (lastIndex > list.Count)
- {
- lastIndex = list.Count;
- }
- for (int i = 0; i < lastIndex; i++)
- {
- Console.Write(list[i] + " "); // Трябва да се принтират на един ред
- }
- //Console.WriteLine(); // Принтираме празен ред
- }
- else if (command == "Last") // Ако не обърнеш листа няма как да принтираш от последния символ, защото се иска при "A B C Q D E F G" и Last 3 да се принтира "E F G", а не "G F D"
- {
- int count = int.Parse(tokens[1]);
- int firstIndex = list.Count - count;
- if (firstIndex < 0)
- {
- firstIndex = 0;
- }
- for (int i = firstIndex; i < list.Count; i++)
- {
- Console.Write(list[i] + " "); // Трябва да се принтират на един ред
- }
- Console.WriteLine(); // Принтираме празен ред
- }
- else if (command == "Print")
- {
- string normalOrReversed = tokens[1];
- if (normalOrReversed == "Normal")
- {
- Console.WriteLine("Frogs: " + string.Join(" ", list)); // Трябва да има празно след :
- break;
- }
- else if (normalOrReversed == "Reversed")
- {
- list.Reverse();
- Console.WriteLine("Frogs: " + string.Join(" ", list)); // Трябва да има празно след :
- break;
- }
- }
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement