Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 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 ConsoleApp2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> numbers = Console.ReadLine().Split(' ').ToList();
  14.             List<string> command = new List<string>();
  15.             command.Add("");
  16.             while (command[0] != "print")
  17.             {
  18.                 command = Console.ReadLine().Split(' ').ToList();
  19.                 if (command[0] == "add")
  20.                 {
  21.                     numbers.Insert(Convert.ToInt32(command[1]), command[2]);
  22.                 }
  23.                 else if (command[0] == "addMany")
  24.                 {
  25.                     int index = Convert.ToInt32(command[1]);
  26.                     command.Remove(command[0]);
  27.                     command.Remove(command[0]);
  28.                     numbers.InsertRange(index, command);
  29.                 }
  30.                 else if (command[0] == "contains")
  31.                 {
  32.                     if (numbers.Contains(command[1]))
  33.                     {
  34.                         for (int i = 0; i < numbers.Count; i++)
  35.                         {
  36.                             if (numbers[i] == command[1])
  37.                             {
  38.                                 Console.WriteLine(i);
  39.                                 break;
  40.                             }
  41.                         }
  42.                     }
  43.                     else
  44.                     {
  45.                         Console.WriteLine(-1);
  46.                     }
  47.                 }
  48.                 else if (command[0] == "remove")
  49.                 {
  50.                     numbers.Remove(numbers[Convert.ToInt32(command[1])]);
  51.                 }
  52.                 else if (command[0] == "shift")       // 0 1 2 3 4 5 6 7 8
  53.                 {
  54.                     for (int y = 1; y <= Convert.ToInt32(command[1]); y++)
  55.                     {
  56.                         string numberToAddAtTheEnd = numbers[0];
  57.                         numbers.Add(numberToAddAtTheEnd);
  58.                         numbers.Remove(numbers[0]);
  59.                     }
  60.                 }
  61.                 else if (command[0] == "sumPairs")
  62.                 {
  63.                     if (numbers.Count % 2 != 0)
  64.                     {
  65.                         numbers.Add("0");
  66.                     }
  67.                     for (int j = numbers.Count - 1; j >= 1; j-=2)
  68.                     {
  69.                         numbers[j] = Convert.ToString(Convert.ToInt32(numbers[j]) + Convert.ToInt32(numbers[j - 1]));
  70.                         numbers.Remove(numbers[j - 1]);
  71.                     }
  72.                 }
  73.             }
  74.             Console.WriteLine("[{0}]", string.Join(", ", numbers));
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement