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