Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _06b_Lists_Exercises
- {
- class Lists_Exercises
- {
- static void Main(string[] args)
- {
- List<int> numList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- List<string> commands = Console.ReadLine().Split(' ').ToList();
- while (commands[0] != "print")
- {
- if (commands[0] == "add")
- {
- numList.Insert(int.Parse(commands[1]), int.Parse(commands[2]));
- }
- else if (commands[0] == "addMany")
- {
- int index = int.Parse(commands[1]);
- numList.InsertRange(index, commands.Skip(2).Select(int.Parse));
- }
- else if (commands[0] == "contains")
- {
- if (numList.Contains(int.Parse(commands[1])))
- {
- Console.WriteLine(numList.IndexOf(int.Parse(commands[1])));
- }
- else
- {
- Console.WriteLine(-1);
- }
- }
- else if (commands[0] == "remove")
- {
- numList.RemoveAt(int.Parse(commands[1]));
- }
- else if (commands[0] == "shift")
- {
- int position = int.Parse(commands[1]) % numList.Count;
- var helper = numList.Skip(position).ToList();
- for (int i = 0; i < position; i++)
- {
- helper.Add(numList[i]);
- }
- numList = helper;
- }
- else if (commands[0] == "sumPairs")
- {
- int cycles = numList.Count / 2;
- for (int i = 0; i < cycles; i++)
- {
- numList[i] += numList[i + 1];
- numList.RemoveAt(i + 1);
- }
- }
- commands = Console.ReadLine().Split(new char[] { ' ' }).ToList();
- }
- Console.WriteLine("[" + string.Join(", ", numList) + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment