Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace fundamental14
- {
- class MainClass
- {
- public static void Main()
- {
- string input = string.Empty;
- List<int> number = Console.ReadLine().Split().Select(int.Parse).ToList();
- //int count = 0;
- List<int>dif = new List<int>(number);
- while((input = Console.ReadLine()) != "end")
- {
- List<string> command = input.Split().ToList();
- if (command[0] == "Contains")
- {
- int amount = int.Parse(command[1]);
- if (number.Contains(amount))
- {
- Console.WriteLine("Yes");
- }
- else
- {
- Console.WriteLine("No such number");
- }
- }
- else if (command[0] == "PrintEven")
- {
- for (int i = 0; i < number.Count; i++)
- {
- if (number[i] % 2 == 0)
- {
- Console.Write($"{number[i]} ");
- }
- }
- Console.WriteLine();
- }
- else if (command[0] == "PrintOdd")
- {
- for (int i = 0; i < number.Count; i++)
- {
- if (number[i] % 2 != 0)
- {
- Console.Write($"{number[i]} ");
- }
- }
- Console.WriteLine();
- }
- else if (command[0] == "GetSum")
- {
- Console.WriteLine(number.Sum());
- }
- else if(command[0] == "Filter")
- {
- int filter = int.Parse(command[2]);
- if (command[1] == ">=")
- {
- for (int i = 0; i < number.Count; i++)
- {
- if (number[i] >= filter)
- {
- Console.Write($"{number[i]} ");
- }
- }
- Console.WriteLine();
- }
- else if (command[1] == "<")
- {
- for (int i = 0; i < number.Count; i++)
- {
- if (number[i] < filter)
- {
- Console.Write($"{number[i]} ");
- }
- }
- Console.WriteLine();
- }
- else if (command[1] == "<=")
- {
- for (int i = 0; i < number.Count; i++)
- {
- if (number[i] <= filter)
- {
- Console.Write($"{number[i]} ");
- }
- }
- Console.WriteLine();
- }
- else if (command[1] == ">")
- {
- for (int i = 0; i < number.Count; i++)
- {
- if (number[i] > filter)
- {
- Console.Write($"{number[i]} ");
- }
- }
- Console.WriteLine();
- }
- }
- else if (command[0] == "Add")
- {
- int amount = int.Parse(command[1]);
- number.Add(amount);
- //count++;
- }
- else if (command[0] == "Remove")
- {
- int amount = int.Parse(command[1]);
- number.Remove(amount);
- //count++;
- }
- else if (command[0] == "RemoveAt")
- {
- int amount = int.Parse(command[1]);
- number.RemoveAt(amount);
- //count++;
- }
- else if (command[0] == "Insert")
- {
- int amount = int.Parse(command[1]);
- int index = int.Parse(command[2]);
- number.Insert(index, amount);
- //count++;
- }
- }
- var compare = (number.All(dif.Contains) && number.Count == dif.Count);
- if (!compare)
- {
- Console.WriteLine(string.Join(" ", number));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement