Advertisement
Guest User

на някъв гей тъпия код

a guest
Jun 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Ex_List_List_Operation
  6. {
  7.     class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.             string command;
  13.  
  14.             while ((command = Console.ReadLine()) != "End")
  15.             {
  16.                 string[] commandLine = command.Split().ToArray();
  17.                 ExecuteCommands(numbers, commandLine);
  18.             }
  19.             Console.WriteLine(String.Join(" ", numbers));
  20.  
  21.         }
  22.         private static void ExecuteCommands(List<int> numbers, string[] commandLine)
  23.         {
  24.             if (commandLine[0] == "Add")
  25.             {
  26.                 numbers.Add(int.Parse(commandLine[1]));
  27.             }
  28.             else if (commandLine[0] == "Remove")
  29.             {
  30.                 int index = int.Parse(commandLine[1]);
  31.                 if (index >= 0 && index < numbers.Count)
  32.                 {
  33.                     numbers.RemoveAt(index);
  34.                 }
  35.                 else
  36.                 {
  37.                     Console.WriteLine("Invalid index");
  38.                 }
  39.             }
  40.             else if (commandLine[0] == "Insert")
  41.             {
  42.                 int index = int.Parse(commandLine[2]);
  43.                 int element = int.Parse(commandLine[1]);
  44.  
  45.                 if (index >= 0 && index < numbers.Count)
  46.                 {
  47.                     numbers.Insert(index, element);
  48.                 }
  49.                 else
  50.                 {
  51.                     Console.WriteLine("Invalid index");
  52.                 }
  53.             }
  54.             else if (commandLine[0] == "Shift")
  55.             {
  56.                 string direction = commandLine[1];
  57.                 int count = int.Parse(commandLine[2]);
  58.                 ShiftList(numbers, direction, count);
  59.             }
  60.         }
  61.         private static void ShiftList(List<int> numbers, string direction, int count)
  62.         {
  63.             if (direction == "left")
  64.             {
  65.                 for (int i = 0; i < count; i++)
  66.                 {
  67.                     int tempNumber = numbers[0];
  68.                     numbers.Add(numbers[0]);
  69.                     numbers.RemoveAt(0);
  70.                 }
  71.             }
  72.             else if (direction == "right")
  73.             {
  74.                 for (int i = 0; i < count; i++)
  75.                 {
  76.                     numbers.Insert(0, numbers[numbers.Count - 1]);
  77.                     numbers.RemoveAt(numbers.Count - 1);
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement