Advertisement
Guest User

1234

a guest
Jun 16th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Lab1RemoveNegatxvesAndReverse
  5. {
  6.     class Program
  7.     {
  8.         public static List<int> nums = new List<int>();
  9.         static void Main(string[] args)
  10.         {
  11.             //Console.WriteLine(5 % 3);
  12.             nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  13.             string[] command = Console.ReadLine().Split(' ').ToArray();
  14.             while (command[0] != "print")
  15.             {
  16.                 switch (command[0])
  17.                 {
  18.                     case "add":
  19.                         nums.Insert(int.Parse(command[1]), int.Parse(command[2]));
  20.                         break;
  21.                     case "addMany":
  22.                         int pos = int.Parse(command[1]);
  23.                         for (int i = 2; i < command.Length; i++)
  24.                         {
  25.                                 nums.Insert(pos, int.Parse(command[i]));
  26.                                 pos++;
  27.                         }
  28.                         break;
  29.                     case "contains":
  30.                         int index = nums.IndexOf(int.Parse(command[1]));
  31.                         Console.WriteLine(index);
  32.                         break;
  33.                     case "remove":
  34.                         nums.RemoveAt(int.Parse(command[1]));
  35.                         break;
  36.                     case "shift":
  37.                         int positions = int.Parse(command[1]) % nums.Count;
  38.                         List<int> moved = new List<int>();
  39.                         for (int i = 0; i < positions; i++)
  40.                         {
  41.                             moved.Add(nums[0]);
  42.                             nums.RemoveAt(0);
  43.                         }
  44.                         nums.AddRange(moved);
  45.                         //for (int i = 0; i < positions; i++)
  46.                         //{
  47.                         //    nums.Add(moved[i]);
  48.                         //}
  49.                         break;
  50.                     case "sumPairs":
  51.                         for (int i = 0; i < nums.Count - nums.Count % 2; i += 2)
  52.                         {
  53.                             nums[i] += nums[i + 1];
  54.                             nums[i + 1] = -1;
  55.                         }
  56.                         nums.RemoveAll(x => x == -1);
  57.                         break;
  58.                     default:
  59.                         Console.WriteLine("Incorrect input. Please write add, addMany, contains, shift or sumPairs");
  60.                         break;
  61.                 }
  62.                 command = Console.ReadLine().Split(' ').ToArray();
  63.  
  64.             }
  65.             Console.WriteLine("[" + string.Join(", ", nums) + "]");
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement