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 ArrayManipulators_3._06._2016
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<long> inputNumbers = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
- List<string> commands = new List<string>();
- int indexCommand = 0;
- do
- {
- commands.Add(Console.ReadLine());
- indexCommand++;
- } while (commands[indexCommand - 1] != "print");
- for (int i = 0; i < commands.Count; i++)
- {
- string[] currentCommand = commands[i].Split(' ');
- switch (currentCommand[0].ToLower())
- {
- case "add":
- inputNumbers.Insert(int.Parse(currentCommand[1]), long.Parse(currentCommand[2]));
- break;
- case "addmany":
- AddMany(inputNumbers, currentCommand);
- break;
- case "contains":
- FindingContainIndex(inputNumbers, currentCommand);
- break;
- case "remove":
- inputNumbers.RemoveAt(int.Parse(currentCommand[1]));
- break;
- case "shift":
- Shift(inputNumbers, currentCommand);
- break;
- case "sumpairs":
- SumPairs(inputNumbers);
- break;
- case "print":
- Console.Write('[');
- Console.Write(string.Join(", ", inputNumbers));
- Console.WriteLine(']');
- break;
- }
- }
- }
- public static void SumPairs(List<long> inputNumbers)
- {
- int countInputNumbers = inputNumbers.Count;
- for (int iPairs = 0; iPairs < countInputNumbers / 2; iPairs++)
- {
- inputNumbers[iPairs] += inputNumbers[iPairs + 1];
- inputNumbers.RemoveAt(iPairs + 1);
- }
- }
- public static void Shift(List<long> inputNumbers, string[] currentCommand)
- {
- int numberOfElements = int.Parse(currentCommand[1]);
- for (int iShift = 0; iShift < numberOfElements; iShift++)
- {
- inputNumbers.Add(inputNumbers[0]);
- inputNumbers.RemoveAt(0);
- }
- }
- public static void FindingContainIndex(List<long> inputNumbers, string[] currentCommand)
- {
- long containNumber = long.Parse(currentCommand[1]);
- Console.WriteLine(inputNumbers.IndexOf(containNumber));
- }
- public static void AddMany(List<long> inputNumbers, string[] command)
- {
- long[] addElements = new long[command.Length - 2];
- // saving add elements
- for (int iSave = 0; iSave < command.Length - 2; iSave++)
- {
- addElements[iSave] = long.Parse(command[iSave + 2]);
- }
- // inserting saved elements at particular index
- for (int iInsert = addElements.Length - 1; iInsert >= 0; iInsert--)
- {
- int index = int.Parse(command[1]);
- inputNumbers.Insert(int.Parse(command[1]), addElements[iInsert]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement