Advertisement
gospod1978

List\List Manipulation Basics

Oct 18th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental14
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             string input = string.Empty;
  12.             List<int> number = Console.ReadLine().Split().Select(int.Parse).ToList();
  13.            
  14.             while((input = Console.ReadLine()) != "end")
  15.             {
  16.                 List<string> command = input.Split().ToList();
  17.                 int amount = int.Parse(command[1]);
  18.                 if (command[0] == "Add")
  19.                 {
  20.                     number.Add(amount);
  21.                 }
  22.                 else if (command[0] == "Remove")
  23.                 {
  24.                     number.Remove(amount);
  25.                 }
  26.                 else if (command[0] == "RemoveAt")
  27.                 {
  28.                     number.RemoveAt(amount);
  29.                 }
  30.                 else if (command[0] == "Insert")
  31.                 {
  32.                     int index = int.Parse(command[2]);
  33.                     number.Insert(index, amount);
  34.                 }
  35.             }
  36.        
  37.         Console.WriteLine(string.Join(" ", number));
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement