Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Array_Manipulator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- List<int> list = input
- .Split(' ')
- .Select(int.Parse)
- .ToList();
- while (input != "print")
- {
- input = Console.ReadLine();
- string[] tokens = input.Split(' ').ToArray();
- if (tokens[0] == "add")
- {
- int index = int.Parse(tokens[1]);
- int element = int.Parse(tokens[2]);
- list.Insert(index, element);
- }
- else if (tokens[0] == "addMany")
- {
- int index = int.Parse(tokens[1]);
- List<int> nums = tokens.Skip(2).Select(int.Parse).ToList();
- list.InsertRange(index, nums);
- }
- else if (tokens[0] == "contains")
- {
- int existing = int.Parse(tokens[1]);
- if (list.Contains(existing))
- {
- for (int i = 0; i < list.Count; i++)
- {
- if (existing == list[i])
- {
- Console.WriteLine(i);
- }
- }
- }
- else
- {
- Console.WriteLine(-1);
- }
- }
- else if (tokens[0] == "remove")
- {
- int index = int.Parse(tokens[1]);
- list.RemoveAt(index);
- }
- else if (tokens[0] == "sumPairs")
- {
- int sum = 0;
- int count = 0;
- List<int> temp = new List<int>();
- for (int i = 0; i < list.Count; i += 2)
- {
- count++;
- if (count <= list.Count / 2)
- {
- sum = list[i] + list[i + 1];
- temp.Add(sum);
- }
- else
- {
- temp.Add(list[i]);
- }
- }
- list.Clear();
- for (int j = 0; j < temp.Count; j++)
- {
- list.Add(temp[j]);
- }
- }
- else if (tokens[0] == "shift")
- {
- int shift = int.Parse(tokens[1]);
- for (int i = 0; i < shift; i++)
- {
- list.Add(list[0]);
- list.Remove(list[0]);
- }
- }
- }
- Console.WriteLine($"[{string.Join(", ", list)}]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement