Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Globalization;
- using System.Security.Cryptography.X509Certificates;
- List<int> numbers = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- string command = Console.ReadLine();
- bool hasChanges = false;
- while (command != "end")
- {
- string[] commandInfo = command.Split();
- if (commandInfo[0] == "Add")
- {
- int number = int.Parse(commandInfo[1]);
- numbers.Add(number);
- hasChanges = true;
- }
- else if (commandInfo[0] == "Remove")
- {
- int number = int.Parse(commandInfo[1]);
- numbers.Remove(number);
- hasChanges = true;
- }
- else if (commandInfo[0] == "RemoveAt")
- {
- int number = int.Parse(commandInfo[1]);
- numbers.RemoveAt(number);
- hasChanges = true;
- }
- else if (commandInfo[0] == "Insert")
- {
- int number = int.Parse(commandInfo[1]);
- int index = int.Parse(commandInfo[2]);
- numbers.Insert(index, number);
- hasChanges = true;
- }
- else if (commandInfo[0] == "Contains")
- {
- int number = int.Parse(commandInfo[1]);
- if (numbers.Contains(number))
- {
- Console.WriteLine("Yes");
- }
- else
- {
- Console.WriteLine("No such number");
- }
- }
- else if (commandInfo[0] == "PrintOdd")
- {
- List<int> oddNumbersList = new List<int>();
- for (int i = 0; i < numbers.Count; i++)
- {
- if (numbers[i] % 2 != 0)
- {
- oddNumbersList.Add(numbers[i]);
- }
- }
- Console.WriteLine(String.Join(" ", oddNumbersList));
- }
- else if (commandInfo[0] == "PrintEven")
- {
- List<int> evenNumbersList = new List<int>();
- for (int i = 0; i < numbers.Count; i++)
- {
- if (numbers[i] % 2 == 0)
- {
- evenNumbersList.Add(numbers[i]);
- }
- }
- Console.WriteLine(String.Join(" ", evenNumbersList));
- }
- else if (commandInfo[0] == "GetSum")
- {
- int sum = 0;
- for (int i = 0; i < numbers.Count; i++)
- {
- sum += numbers[i];
- }
- Console.WriteLine(sum);
- }
- else if (commandInfo[0] == "Filter")
- {
- List<int> conditionList = new List<int>();
- string condition = commandInfo[1];
- int number = int.Parse(commandInfo[2]);
- if (condition == "<")
- {
- foreach (var item in numbers)
- {
- if (item < number)
- {
- conditionList.Add(item);
- }
- }
- }
- if (condition == ">")
- {
- foreach (var item in numbers)
- {
- if (item > number)
- {
- conditionList.Add(item);
- }
- }
- }
- if (condition == ">=")
- {
- foreach (var item in numbers)
- {
- if (item >= number)
- {
- conditionList.Add(item);
- }
- }
- }
- if (condition == "<=")
- {
- foreach (var item in numbers)
- {
- if (item <= number)
- {
- conditionList.Add(item);
- }
- }
- }
- Console.WriteLine(String.Join(" ", conditionList));
- }
- command = Console.ReadLine();
- }
- if (hasChanges)
- {
- Console.WriteLine(string.Join(" ", numbers));
- }
Add Comment
Please, Sign In to add comment