Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ListManipulationAdvanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> num = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- string[] tokens = Console.ReadLine().Split();
- bool isCharged = false;
- while (tokens[0].ToLower() != "end")
- {
- switch (tokens[0].ToLower())
- {
- case "add":
- int numToAdd = int.Parse(tokens[1]);
- num.Add(numToAdd);
- isCharged = true;
- break;
- case "remove":
- int numToRemove = int.Parse(tokens[1]);
- num.Remove(numToRemove);
- isCharged = true;
- break;
- case "removeat":
- int indexToRemoveAt = int.Parse(tokens[1]);
- num.RemoveAt(indexToRemoveAt);
- isCharged = true;
- break;
- case "insert":
- int numToInsert = int.Parse(tokens[1]);
- int indexToInsert = int.Parse(tokens[2]);
- num.Insert(indexToInsert, numToInsert);
- isCharged = true;
- break;
- case "contains":
- Console.WriteLine(num.Contains(int.Parse(tokens[1])) ? "Yes" : "No such number");
- break;
- case "printeven":
- Console.WriteLine(string.Join(" ", num.Where(n => n % 2 == 0)));
- break;
- case "printodd":
- Console.WriteLine(string.Join(" ", num.Where(n => n % 2 == 1)));
- break;
- case "getsum":
- Console.WriteLine(num.Sum());
- break;
- case "filter":
- if (tokens[1] == "<")
- {
- Console.WriteLine(string.Join(" ", num.Where(n => n < int.Parse(tokens[2]))));
- }
- else if (tokens[1] == ">")
- {
- Console.WriteLine(string.Join(" ", num.Where(n => n > int.Parse(tokens[2]))));
- }
- else if (tokens[1] == "<=")
- {
- Console.WriteLine(string.Join(" ", num.Where(n => n <= int.Parse(tokens[2]))));
- }
- else if (tokens[1] == ">=")
- {
- Console.WriteLine(string.Join(" ", num.Where(n => n >= int.Parse(tokens[2]))));
- }
- break;
- }
- tokens = Console.ReadLine().Split();
- }
- if (isCharged)
- {
- Console.WriteLine(string.Join(" ", num));
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment