Advertisement
Guest User

Untitled

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