Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _1._6.List_Manipulation_Basics
- {
- class Program
- {
- // 1. Правя лист от int +++
- // 2. Докато не получа команда "end", ще получавам ще получавам различни команди +++
- // 3. Commands:
- // Add {number}: add a number to the end of the list. +++
- // Remove { number}: remove a number from the list. +++
- // RemoveAt { index}: remove a number at a given index. +++
- // Insert { number} { index}: insert a number at a given index. +++
- static void Main()
- {
- List<int> inNums = Console.ReadLine().Split().Select(int.Parse).ToList();
- while (true)
- {
- List<string> command = Console.ReadLine().Split().ToList();
- string findResult = command.Find(result => result == command[0]);
- if (findResult == "end")
- {
- break;
- }
- else if (findResult == "Add")
- {
- int numAdd = int.Parse(command[1]);
- inNums.Add(numAdd);
- }
- else if (findResult == "Remove")
- {
- int numRemove = int.Parse(command[1]);
- inNums.Remove(numRemove);
- }
- else if (findResult == "RemoveAt")
- {
- int numRemoveAt = int.Parse(command[1]);
- inNums.RemoveAt(numRemoveAt);
- }
- else
- {
- int insertElement = int.Parse(command[1]);
- int insertIndex = int.Parse(command[2]);
- inNums.Insert(insertIndex, insertElement);
- }
- }
- Console.WriteLine(string.Join(" ", inNums));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment