Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             Dictionary<string, Func<int, int, int>> operations = new Dictionary<string, Func<int, int, int>>
  6.             {
  7.                 {"+", (x,y) => x + y }
  8.                 ,{"-", (x,y) => x - y }
  9.                 ,{"/", (x,y) => x / y }
  10.                 ,{"*", (x,y) => x * y }
  11.                 ,{"%", (x,y) => x % y }
  12.             };
  13.  
  14.             var input = new StringReader(@"+ 7 9
  15. - 0 4
  16. * 5 6
  17. / 8 3
  18. % 5 2");
  19.             string line = input.ReadLine();
  20.             string result = string.Empty;
  21.             while(line != null)
  22.             {
  23.                 var operation = line.Split(' ');
  24.                 result += Convert.ToString(operations[operation[0]](Convert.ToInt32(operation[1]), Convert.ToInt32(operation[2]))) + "\n";
  25.                 line = input.ReadLine();
  26.             }
  27.  
  28.             Console.Write(result);
  29.             Console.Read();
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement