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 ArrayManipulator
- {
- class ArrayManipulator
- {
- static void Main(string[] args)
- {
- var numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- string command = Console.ReadLine();
- while (command != "print")
- {
- List<string> commandList = command.Split().ToList();
- if (commandList[0] == "add")
- {
- int index = int.Parse(commandList[1]);
- int element = int.Parse(commandList[2]);
- numbers.Insert(index, element);
- }
- else if (commandList[0] == "addMany")
- {
- int index = int.Parse(commandList[1]);
- List<int> numsToAdd = new List<int>();
- for (int i = 2; i < commandList.Count; i++)
- {
- numsToAdd.Add(int.Parse(commandList[i]));
- }
- numbers.InsertRange(index, numsToAdd);
- }
- else if (commandList[0] == "contains")
- {
- int element = int.Parse(commandList[1]);
- if (numbers.Contains(element))
- {
- Console.WriteLine(numbers.IndexOf(element));
- }
- else
- {
- Console.WriteLine("-1");
- }
- }
- else if (commandList[0] == "remove")
- {
- int index = int.Parse(commandList[1]);
- numbers.RemoveAt(index);
- }
- else if (commandList[0] == "shift")
- {
- int positions = int.Parse(commandList[1]);
- for (int i = 0; i < positions; i++)
- {
- int temp = numbers[0];
- numbers.RemoveAt(0);
- numbers.Add(temp);
- }
- }
- else if (commandList[0] == "sumPairs")
- {
- numbers = SumPairs(numbers);
- }
- command = Console.ReadLine();
- }
- Console.WriteLine("[{0}]", string.Join(", ", numbers));
- }
- static List<int> SumPairs(List<int> sums)
- {
- List<int> temp = new List<int>();
- for (int s = 0; s < 1; s++)
- {
- for (int i = 0; i < sums.Count - 1; i++)
- {
- temp.Add(sums[i] + sums[i + 1]);
- i = i + 1;
- }
- if (sums.Count % 2 != 0)
- {
- temp.Add(sums[sums.Count - 1]);
- }
- }
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement