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