Advertisement
desislava_topuzakova

05. Applied Arithmetics

Jun 3rd, 2022
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _5._Applied_Arithmetics
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13.             //PRINT: получаваме списък -> принтираме списъка
  14.             Action<List<int>> print = list => Console.WriteLine(String.Join(" ", list));
  15.  
  16.             Func<List<int>, List<int>> operation = null; //обща функция за add, multiply, subtract
  17.  
  18.             string command = Console.ReadLine();
  19.  
  20.             while (command != "end")
  21.             {   //command = "add" или "multiply" или "subtract" или "print"
  22.                 switch (command)
  23.                 {
  24.                     case "add":
  25.                         operation = list => list.Select(number => number += 1).ToList();
  26.                         numbers = operation(numbers);
  27.                         break;
  28.                     case "multiply":
  29.                         operation = list => list.Select(number => number *= 2).ToList();
  30.                         numbers = operation(numbers);
  31.                         break;
  32.                     case "subtract":
  33.                         operation = list => list.Select(number => number -= 1).ToList();
  34.                         numbers = operation(numbers);
  35.                         break;
  36.                     case "print":
  37.                         print(numbers);
  38.                         break;
  39.                 }
  40.  
  41.                 command = Console.ReadLine();
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement