Advertisement
Guest User

05. Applied Arithmetics

a guest
Feb 4th, 2018
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _05.AppliedArithmetics
  5. {
  6.     class Program
  7.     {
  8.         private static int[] numbers;
  9.         static void Main()
  10.         {
  11.             numbers = Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse).ToArray();
  13.  
  14.             string command = Console.ReadLine();
  15.             Action<string> manipulateNums = operation =>
  16.             {
  17.                 switch (operation)
  18.                 {
  19.                     case "add":
  20.                         numbers = numbers.Select(n => n++).ToArray();
  21.                         break;
  22.                     case "multiply":
  23.                         numbers = numbers.Select(n => n * 2).ToArray();
  24.                         break;
  25.                     case "subtract":
  26.                         numbers = numbers.Select(n => n--).ToArray();
  27.                         break;
  28.                     case "print":
  29.                         Console.WriteLine(string.Join(" ", numbers));
  30.                         break;
  31.                 }
  32.             };
  33.  
  34.             while (command != "end")
  35.             {
  36.                 manipulateNums(command);
  37.  
  38.                 command = Console.ReadLine();
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement