fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class M
  5. {
  6. double d(double[]a) {
  7. Array.Reverse(a);
  8. var s = new Stack<double>(a);
  9. int i=0,j;
  10. while (s.Count>1)
  11. {
  12. double l=s.Pop(),r=s.Pop();
  13. j=i++%5;
  14. s.Push(j==0?l+r:j==1?l-r:j==2?l*r:j==3?l/r:Math.Pow(l, r));
  15. }
  16. return s.Peek();
  17. }
  18.  
  19. public static void Main()
  20. {
  21. int[][] a = new int[][]{
  22. new int[]{1,2,3,4,5},
  23. new int[]{5,12,23,2,4,4,2,6,7},
  24. new int[]{-8,50,3,3,-123,4,17,99,13},
  25. new int[]{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
  26. new int[]{1,0,1,0,1,0},
  27. new int[]{-9,-8,-1},
  28. new int[]{0,-3},
  29. new int[]{-99}
  30. };
  31.  
  32. for (int i = 0; i < a.Length; i++)
  33. {
  34. Console.WriteLine(new M().d(Array.ConvertAll(a[i], e => Convert.ToDouble(e))));
  35. }
  36. Console.ReadKey();
  37. }
  38. }
Success #stdin #stdout 0.05s 24096KB
stdin
Standard input is empty
stdout
0
539
-1055.35694384628
256
1
-16
-3
-99