Advertisement
mimiiovkova

Untitled

Oct 9th, 2020 (edited)
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Applied_Arithmetics
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.             string command = "";
  13.             Action<List<int>> print = x => Console.WriteLine(string.Join(" ", x));
  14.  
  15.             while ((command = Console.ReadLine()) != "end")
  16.             {
  17.                 Func<List<int>, List<int>> operation = command switch
  18.                 {
  19.                     "add" => numbers => numbers.Select(a => a++).ToList(),
  20.                     "multiply" => numbers => numbers.Select(a => a *= 2).ToList(),
  21.                     "subtract" => numbers => numbers.Select(a => a--).ToList(),
  22.                     _ => null
  23.                 };
  24.  
  25.                 if (command == "print")
  26.                 {
  27.                     print(numbers);
  28.                 }
  29.             }
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement