Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ListManipulationBasics
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> num = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- while (true)
- {
- string line = Console.ReadLine().ToLower();
- if (line == "end")
- {
- break;
- }
- string[] tokens = line.Split();
- switch (tokens[0])
- {
- case "add":
- int numToAdd = int.Parse(tokens[1]);
- num.Add(numToAdd);
- break;
- case "remove":
- int numToRemove = int.Parse(tokens[1]);
- num.Remove(numToRemove);
- break;
- case "removeat":
- int indexToRemoveAt = int.Parse(tokens[1]);
- num.RemoveAt(indexToRemoveAt);
- break;
- case "insert":
- int numToInsert = int.Parse(tokens[1]);
- int indexToInsert = int.Parse(tokens[2]);
- num.Insert(indexToInsert, numToInsert);
- break;
- }
- }
- Console.WriteLine(string.Join(' ', num));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement