Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _05.Array_Manipulator
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> list = Console.ReadLine().Split().Select(int.Parse).ToList();
- string input = Console.ReadLine();
- string[] command = input.Split().ToArray();
- string commandword = command[0];
- while (commandword!="print")
- {
- if (commandword=="add")
- {
- int index = int.Parse(command[1]);
- int value = int.Parse(command[2]);
- list.Insert(index, value);
- }
- else if (commandword == "addMany")
- {
- int index = int.Parse(command[1]);
- int[] parsed = new int[command.Length-2];
- for (int i = 2; i < command.Length; i++)
- {
- parsed[i-2] = int.Parse(command[i]);
- }
- list.InsertRange(index, parsed);
- }
- else if (commandword=="contains")
- {
- int magic = int.Parse(command[1]);
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i] == magic)
- {
- Console.WriteLine(i);break;
- }
- if (i==list.Count-1)
- {
- Console.WriteLine(-1);
- }
- }
- }
- else if (commandword == "remove")
- {
- int index = int.Parse(command[1]);
- list.RemoveAt(index);
- }
- else if (commandword == "shift")
- {
- int positions = int.Parse(command[1]);
- for (int j = 0; j < positions; j++)
- {
- int temp = list[0];
- for (int i = 0; i < list.Count - 1; i++)
- {
- list[i] = list[i + 1];
- }
- list[list.Count - 1] = temp;
- }
- }
- else if (commandword == "sumPairs")
- {
- for (int i = list.Count-1; i >0; i-=2)
- {
- list[i-1] =list[i]+ list[i- 1];
- list.RemoveAt(i);
- }
- }
- input = Console.ReadLine();
- command = input.Split().ToArray();
- commandword = command[0];
- }
- Console.Write("[");
- Console.Write(string.Join(", ",list));
- Console.Write("]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement