Guest User

Untitled

a guest
Oct 15th, 2017
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.ArrayManipulator
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers =
  14.                 Console.ReadLine()
  15.                 .Split(' ')
  16.                 .Select(int.Parse)
  17.                 .ToList();
  18.             string[] commands =
  19.                 Console.ReadLine()
  20.                 .Split(' ')
  21.                 .ToArray();
  22.  
  23.             while (commands[0] != "print")
  24.             {
  25.  
  26.                 if (commands[0] == "add")
  27.                 {
  28.                     int index = int.Parse(commands[1]);
  29.                     int element = int.Parse(commands[2]);
  30.                     numbers.Insert(index, element);
  31.                 }
  32.  
  33.                 else if (commands[0]=="addMany")
  34.                 {
  35.                     int index = int.Parse(commands[1]);
  36.                     List<int> a = new List<int>();
  37.                     for (int i = 2; i < commands.Length; i++)
  38.                     {
  39.                         numbers.Insert(index, int.Parse(commands[i]));
  40.                         index++;
  41.                     }
  42.                 }
  43.  
  44.                 else if(commands[0]=="contains")
  45.                 {
  46.                     int index = numbers.IndexOf((int.Parse(commands[1])));
  47.                     Console.WriteLine(index);
  48.                 }
  49.  
  50.                 else if (commands[0] == "remove")
  51.                 {
  52.                     int index = int.Parse(commands[1]);
  53.                     numbers.RemoveAt(index);
  54.                 }
  55.  
  56.                 else if (commands[0]== "shift")
  57.                 {
  58.                     int index = int.Parse(commands[1]);
  59.                     List<int> a = new List<int>();
  60.                     for (int i = 0; i < index; i++)
  61.                     {
  62.                         a.Add(numbers[i]);
  63.                         numbers.RemoveAt(i);
  64.                     }
  65.  
  66.                     numbers.AddRange(a);
  67.                 }
  68.  
  69.                 else if (commands[0] == "sumPairs")
  70.                 {
  71.                     List<int> a = new List<int>(numbers);
  72.                     for (int i = 0; i < numbers.Count; i++)
  73.                     {                      
  74.                         if (i<numbers.Count-1)
  75.                         {
  76.                             int b = numbers[i] + numbers[i + 1];
  77.                             numbers.RemoveAt(i+1);
  78.                             numbers.RemoveAt(i);
  79.                             numbers.Insert(i, b);
  80.                         }
  81.                     }
  82.                 }
  83.  
  84.                 commands =
  85.                 Console.ReadLine()
  86.                 .Split(' ')
  87.                 .ToArray();
  88.             }
  89.  
  90.             Console.WriteLine("["+string.Join(", ", numbers)+ "]");
  91.  
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment