Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ListManipulation
- {
- class Program
- {
- private static List<int> numbers;
- static void Main(string[] args)
- {
- numbers = Console.ReadLine()
- .Split(' ')
- .Select(int.Parse)
- .ToList();
- string command = Console.ReadLine();
- while (command != "End")
- {
- ProcessCommand(command);
- command = Console.ReadLine();
- }
- }
- static void ProcessCommand(string command)
- {
- string[] commandInfo = command.Split(' ');
- string commandName = commandInfo[0];
- switch (commandName)
- {
- case "add":
- Add(commandInfo);
- break;
- case "addMany":
- AddMany(commandInfo);
- break;
- case "contains":
- Contains(commandInfo);
- break;
- case "remove":
- Remove(commandInfo);
- break;
- case "shift":
- Shift(commandInfo);
- break;
- case "sumPairs":
- SumPairs(commandInfo);
- break;
- case "print":
- Print(commandInfo);
- break;
- default:
- break;
- }
- }
- public static void Add(string[] commandInfo)
- {
- int index = int.Parse(commandInfo[1]);
- int value = int.Parse(commandInfo[2]);
- numbers.Insert(index, value);
- }
- public static void AddMany(string[] commandInfo)
- {
- //addMany 2 38 48 2983 58 923
- int[] numbersToAdd = commandInfo
- .Skip(1) //skip the command name
- .Select(int.Parse)
- .ToArray();
- numbers.AddRange(numbersToAdd);
- }
- public static void Contains(string[] commandInfo)
- {
- int searchedItem = int.Parse(commandInfo[1]);
- int foundIndex = numbers.IndexOf(searchedItem);
- Console.WriteLine(foundIndex);
- }
- public static void Remove(string[] commandInfo)
- {
- int index = int.Parse(commandInfo[1]);
- numbers.RemoveAt(index);
- }
- public static void Shift(string[] commandInfo)
- {
- int rotationElements = int.Parse(commandInfo[1]);
- List<int> startList = numbers
- .Skip(rotationElements)
- .ToList();
- List<int> endList = numbers
- .Take(rotationElements)
- .ToList();
- startList.AddRange(endList);
- numbers = startList;
- }
- public static void SumPairs(string[] commandInfo)
- {
- }
- public static void Print(string[] commandInfo)
- {
- Console.WriteLine(string.Join(" ", numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement