Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Reflection.Metadata;
- namespace _5._Applied_Arithmetics
- {
- class Program
- {
- static void Main(string[] args)
- {
- //---------------------------- VARIANT TYPE 1-------------------------------------------
- //---------- Using ternary operator-----------------------------------------
- //List<int> numbers = new List<int>(Console.ReadLine().Split().Select(int.Parse).ToList());
- //Func<List<int>, string, List<int>> func = (collection, filter) =>
- // (filter == "add" ? collection.Select(n => n += 1) :
- // filter == "subtract" ? collection.Select(n => n -= 1) :
- // collection.Select(n => n *= 2)).ToList();
- //Action<List<int>> print = collection =>
- //{
- // Console.WriteLine(string.Join(" ", collection));
- //};
- //string command = Console.ReadLine();
- //while (command?.ToLower() != "end")
- //{
- // switch (command)
- // {
- // case "add":
- // case "subtract":
- // case "multiply":
- // numbers = func(numbers, command);
- // break;
- // case "print":
- // print(numbers);
- // break;
- // }
- // command = Console.ReadLine();
- //}
- List<int> numbers = new List<int>(Console.ReadLine().Split().Select(int.Parse).ToList());
- Action<List<int>> print = collection =>
- {
- Console.WriteLine(string.Join(" ", collection));
- };
- string command = Console.ReadLine();
- while (command?.ToLower() != "end")
- {
- switch (command)
- {
- case "add":
- numbers = ForEach(numbers, n => n += 1);
- break;
- case "subtract":
- numbers = ForEach(numbers, n => n -= 1);
- break;
- case "multiply":
- numbers = ForEach(numbers, n => n *= 2);
- break;
- case "print":
- print(numbers);
- break;
- }
- command = Console.ReadLine();
- }
- }
- public static List<int> ForEach(List<int> numbers, Func<int, int> func) => (numbers.Select(number => func(number)).ToList());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment