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 Lists
- {
- public class Lists
- {
- public static void Main()
- {
- var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- var command = Console.ReadLine().Split(' ').ToList();
- while (command[0] !="print")
- {
- switch (command[0])
- {
- case "add":
- {
- var index = int.Parse(command[1]);
- var element = int.Parse(command[2]);
- input.Insert(index, element);
- break;
- }
- case "remove":
- {
- var index = int.Parse(command[1]);
- input.RemoveAt(index);
- break;
- }
- case "contains":
- {
- var element = int.Parse(command[1]);
- int index = input.FindIndex(a => a == element);
- Console.WriteLine(index);
- break;
- }
- case "sumPairs":
- {
- for (int i = 0; i < input.Count; i++)
- {
- input[i] += input[i + 1];
- input.RemoveAt(i + 1);
- }
- break;
- }
- case "shift":
- {
- var positions = int.Parse(command[1]);
- RotateLeft(input, positions);
- break;
- }
- case "addMany":
- {
- var pos = int.Parse(command[1]);
- if (pos > input.Count)
- {
- break;
- }
- for (int i = command.Count - 1; i >= 2; i--)
- {
- input.Insert(pos, (int.Parse)(command[i]));
- }
- break;
- }
- }
- command = Console.ReadLine().Split(' ').ToList();
- }
- Console.WriteLine($"[{string.Join(", ", input)}]");
- }
- public static void RotateLeftOnce(List<int> input)
- {
- var numToSwitch = input[0];
- for (var i = 0; i < input.Count; i += 1)
- {
- if (i + 1 < input.Count)
- {
- var switcher = input[i];
- input[i] = input[i + 1];
- input[i + 1] = switcher;
- }
- }
- }
- public static void RotateLeft(List<int> input, int positions)
- {
- for (var i = 0; i < positions; i += 1)
- {
- RotateLeftOnce(input);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment