Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("ERROR: should pass 3 args.\n\tusage: calculator <a> <operator> <b>");
                return;
            }


            int a = int.Parse(args[0]);
            int b = int.Parse(args[2]);

            OpDelegate op = Mul;

            switch (args[1])
            {
            case "+":
                op = Add;
                break;

            case "-":
                op = Sub;
                break;

            case "*":
                op = Mul;
                break;

            case "/":
                Console.WriteLine(Div(a, b));
                return;
            }
            Console.WriteLine(op(a, b));
        }
Exemplo n.º 2
0
        public SegmentTree(T[] arr, T defValue, OpDelegate operation)
        {
            var n    = arr.Length;
            var t    = (int)(Math.Ceiling(Math.Log(n) / Math.Log(2)));
            var size = (1 << (t + 1)) - 1;

            data           = new T[size];
            this.defValue  = defValue;
            this.operation = operation;
            len            = n;

            BuildTree(arr, 0, n - 1, 0);
        }