MiroslavKisov

AppliedArithmetich

Feb 2nd, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace AppliedArithmetics
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             Func<int, int> subtract = n => n -= 1;
  12.             Func<int, int> add = n => n += 1;
  13.             Func<int, int> multuply = n => n *= 2;
  14.             Action<List<int>> print = arr => Console.WriteLine(string.Join(" ", arr));
  15.             var numbers = Console.ReadLine()
  16.                 .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  17.                 .Select(int.Parse)
  18.                 .ToList();
  19.             string command;
  20.             while((command = Console.ReadLine()) != "end")
  21.             {
  22.                 if (command == "subtract")
  23.                 {
  24.                    numbers = numbers.Select(subtract).ToList();
  25.                 }
  26.                 else if (command == "add")
  27.                 {
  28.                     numbers = numbers.Select(add).ToList();
  29.                 }
  30.                 else if(command == "multiply")
  31.                 {
  32.                     numbers = numbers.Select(multuply).ToList();
  33.                 }
  34.                 else if(command == "print")
  35.                 {
  36.                     print(numbers);
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment