Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03.FroggySquad
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> frogs = Console.ReadLine().Split().ToList();
- string[] command = Console.ReadLine().Split();
- string word = command[0];
- while (word != "Print")
- {
- if (word == "Join")
- {
- string name = command[1];
- frogs.Add(name);
- }
- else if (word == "Jump")
- {
- string name = command[1];
- int index = int.Parse(command[2]);
- if (index >= 0 && index < frogs.Count)
- {
- frogs.Insert(index, name);
- }
- }
- else if (word == "Dive")
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < frogs.Count)
- {
- frogs.RemoveAt(index);
- }
- }
- else if (word == "First")
- {
- int count = int.Parse(command[1]);
- if (count > frogs.Count)
- {
- count = frogs.Count;
- }
- List<string> first = new List<string>();
- for (int i = 0; i < count; i++)
- {
- first.Add(frogs[i]);
- }
- Console.WriteLine(string.Join(" ", first));
- }
- else if (word == "Last")
- {
- int count = int.Parse(command[1]);
- if (count > frogs.Count)
- {
- count = frogs.Count;
- }
- List<string> last = new List<string>();
- List<string> copyFrogs = frogs.ToList();
- for (int i = count; i > 0; i--)
- {
- last.Add(copyFrogs[copyFrogs.Count - 1]);
- copyFrogs.RemoveAt(copyFrogs.Count - 1);
- }
- last.Reverse();
- Console.WriteLine(string.Join(" ", last));
- }
- command = Console.ReadLine().Split();
- word = command[0];
- }
- if (word == "Print")
- {
- if (command[1] == "Normal")
- {
- Console.WriteLine("Frogs: " + string.Join(" ", frogs));
- }
- else if (command[1] == "Reversed")
- {
- frogs.Reverse();
- Console.WriteLine("Frogs: " + string.Join(" ", frogs));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment