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 ConsoleApp95
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToList();
- string[] commands = Console.ReadLine().Split(' ');
- while (commands[0] != "print")
- {
- if (commands[0] == "add")
- {
- int index = int.Parse(commands[1]);
- int element = int.Parse(commands[2]);
- numbers.Insert(index, element);
- }
- if (commands[0] == "addMany")
- {
- int index = int.Parse(commands[1]);
- for (int i = commands.Length -1; i >= 2; i--)
- {
- int element = int.Parse(commands[i]);
- numbers.Insert(index, element);
- }
- }
- if (commands[0] == "contains")
- {
- int element = int.Parse(commands[1]);
- if(numbers.Contains(element))
- {
- Console.WriteLine("{0}", numbers.IndexOf(element));
- }
- else
- {
- Console.WriteLine("-1");
- }
- }
- if (commands[0] == "remove")
- {
- int index = int.Parse(commands[1]);
- numbers.RemoveAt(index);
- }
- if (commands[0] == "shift")
- {
- for (int i = 0; i < int.Parse(commands[1]) % numbers.Count; i++)
- {
- numbers.Add(numbers[0]);
- numbers.RemoveAt(0);
- }
- }
- if (commands[0] == "sumPairs")
- {
- List<int> sum = new List<int>();
- while (numbers.Count >= 2)
- {
- sum.Add(numbers[0] + numbers[1]);
- numbers.RemoveAt(0);
- numbers.RemoveAt(0);
- }
- if (numbers.Count == 1) sum.Add(numbers[0]);
- numbers = sum;
- }
- commands = Console.ReadLine().Split(' ');
- }
- Console.WriteLine($"[{string.Join(", ", numbers)}]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement