Esempio n. 1
0
        // We call it after correct input field text
        public void OnValueChangeInputField()
        {
            BInputField bInputField = inputField.GetComponent <BInputField> ();

            // Yes, It is a little bit dirty, but It is simple and it works :)
            if (!bInputField.doNotHandleEvent)
            {
                var str = inputField.text;

                // Getting the clear string - without the result (anwer) part
                str = BInputField.RemoveTextAfterEqual(str);

                str = str.Trim();

                var d = RPN.Calculate(str);

                // We show a result if we have it and if result is not the input string
                if (IsResult(str, d))
                {
                    str += " = " + d.ToString();
                }

                // We are preventing loop on value change
                bInputField.doNotHandleEvent = true;
                inputField.text = str;
                bInputField.doNotHandleEvent = false;
            }
        }
Esempio n. 2
0
 static void Main(string[] args)
 {
     while (true)                                              //Бесконечный цикл
     {
         Console.Write("Input: ");                             //Предлагаем ввести выражение
         Console.WriteLine(RPN.Calculate(Console.ReadLine())); //Считываем, и выводим результат
     }
 }
Esempio n. 3
0
        static void Calc()
        {
            Console.Write("Калькулятор. Задайте выражение вида 2*(2.5+1.5):\r\n");
            var input = Console.ReadLine();

            if (Regex.IsMatch(input, "[a-zA-Z]") || String.IsNullOrEmpty(input))
            {
                Console.WriteLine("Введены буквы или строка пуста. Расчет невозможен.");
                return;
            }

            Console.WriteLine("Результат: " + RPN.Calculate(input));
        }
Esempio n. 4
0
        private void btnResult4_Click(object sender, EventArgs e)
        {
            bool check = true;
            int  len   = txt1.Text.Length;

            if (txt1.Text[len - 1].ToString() == "+" || txt1.Text[len - 1].ToString() == "-" || txt1.Text[len - 1].ToString() == "*" || txt1.Text[len - 1].ToString() == "/")
            {
                check = false;
            }
            if (qavsOchish != qavsYopish || check == false)
            {
                MessageBox.Show("Error");
            }
            else
            {
                txt2.Text = RPN.Calculate(txt1.Text).ToString();
            }
        }
Esempio n. 5
0
        /*
         * void Generate ()
         * {
         *      //	Log.Add ("Generate");
         *
         *      Debug.Log ("Generate");
         *
         *      var r = new System.Random ();
         *      for (int i=0; i<3; i++) {
         *
         *              ar [i] = r.NextDouble ();
         *              Debug.Log (ar [i]);
         *              Thread.Sleep (0);
         *      }
         * }
         */

        void Test(string s, string answer)
        {
            var d = RPN.Calculate(s);

            var result = "";

            // We show a result if we have it and if result is not the input string
            if (IsResult(s, d))
            {
                result = d.ToString();
                s     += " = " + result;
            }

            // Show test result in my Log Canvas. Yes, I made this Log Canvas myself :)
            if (result == answer)
            {
                Log.Add(s);
            }
            else
            {
                Log.Error(s + ", result: " + result + ", answer: " + answer);
            }
        }
Esempio n. 6
0
        public ActionResult Filter(string func)
        {
            //string func = "[Java>40]&[PHP>40]";
            List <string> comps = new List <string>();
            var           mat   = Regex.Matches(func, @"(?<=\[)(.+?)(?=\])");

            IQueryable <int>[] set = new IQueryable <int> [mat.Count + 1];
            set[0] = db.Student.Select(c => c.StudentId);
            for (int i = 0; i < mat.Count; i++)
            {
                string comp = mat[i].Value.Split('>')[0];
                comps.Add(comp);
                int value = Convert.ToInt32(mat[i].Value.Split('>')[1]);
                set[i + 1] = db.Mark.Where(c => c.Competence.Type == comp && c.Score > value).Select(c => c.StudentId);
            }

            var func_result = RPN.Calculate(set, replace_index(func)).ToList();

            search_result[] results = new search_result[mat.Count];
            if (func_result.Count == 0)
            {
                return(null);
            }
            //var result = db.Mark.Where(u => func_result.Contains(u.StudentId) && comps.Contains(u.Competence.Type)).Select(c=>new { Competence=c.Competence.Type,Student=c.Student.FIO,Score=c.Score});
            for (int i = 0; i < comps.Count; i++)
            {
                var temp = comps[i];

                var s = db.Mark.Where(u => func_result.Contains(u.StudentId) && u.Competence.Type == temp).ToArray().Select(c => new search_result.mark {
                    Student = c.Student.FIO, Score = c.Score
                }).ToArray();
                results[i].competence = temp;
                results[i].marks      = s;
            }
            return(Json(results, JsonRequestBehavior.AllowGet));
        }
Esempio n. 7
0
    public void setTextToInputField()
    {
        String txt = EventSystem.current.currentSelectedGameObject.GetComponentInChildren <Text>().text;

        if (inputField.text.Equals("Invalid expression"))
        {
            inputField.text = "0";
        }

        switch (txt)
        {
        case "=":
            if (!(inputField.text[inputField.text.Length - 1].Equals('*')) &&
                !(inputField.text[inputField.text.Length - 1].Equals('+')) &&
                !(inputField.text[inputField.text.Length - 1].Equals('-')) &&
                !(inputField.text[inputField.text.Length - 1].Equals('/')))
            {
                try
                {
                    inputField.text = RPN.Calculate(inputField.GetComponent <InputField>().text).ToString();
                }
                catch
                {
                    inputField.text = "Invalid expression";
                }
            }
            break;

        case "C":
            inputField.text = "0";
            break;

        case "<-":
            if (inputField.text.Length > 1)
            {
                inputField.text = inputField.text.Substring(0, inputField.text.Length - 1);
            }
            else
            {
                inputField.text = "0";
            }
            break;

        case ".":
            if (inputField.text.Equals(""))
            {
                inputField.text = "0.";
            }
            else
            {
                inputField.text = inputField.text + txt;
            }
            break;

        case "(":
            if (inputField.text.Length != 0 && !inputField.text.Equals("0"))
            {
                if (!(inputField.text[inputField.text.Length - 1].Equals('*') ||
                      inputField.text[inputField.text.Length - 1].Equals('-') ||
                      inputField.text[inputField.text.Length - 1].Equals('+') ||
                      inputField.text[inputField.text.Length - 1].Equals('/')))
                {
                    if (inputField.text[inputField.text.Length - 1].Equals('.'))
                    {
                        inputField.text = inputField.text.Substring(0, inputField.text.Length - 1) + "*(";
                    }
                    else if (inputField.text[inputField.text.Length - 1].Equals('('))
                    {
                        inputField.text = inputField.text + "(";
                    }
                    else
                    {
                        inputField.text = inputField.text + "*(";
                    }
                }

                else
                {
                    inputField.text = inputField.text + "(";
                }
            }
            else
            {
                inputField.text = "(";
            }

            break;

        case ")":
            if (inputField.text.Length != 0)
            {
                if (!(inputField.text[inputField.text.Length - 1].Equals('*') ||
                      inputField.text[inputField.text.Length - 1].Equals('-') ||
                      inputField.text[inputField.text.Length - 1].Equals('+') ||
                      inputField.text[inputField.text.Length - 1].Equals('/') ||
                      inputField.text[inputField.text.Length - 1].Equals('.') ||
                      inputField.text[inputField.text.Length - 1].Equals('(')))
                {
                    inputField.text = inputField.text + ")";
                }
                else if (inputField.text[inputField.text.Length - 1].Equals('('))
                {
                    inputField.text = inputField.text.Substring(0, inputField.text.Length - 1);
                }
                else
                {
                    inputField.text = inputField.text.Substring(0, inputField.text.Length - 1) + ")";
                }
            }

            break;

        default:
            if (!(inputField.text.Equals("0") || inputField.text.Equals("")))
            {
                if (txt.Equals("*") || txt.Equals("/") || txt.Equals("+") || txt.Equals("-"))
                {
                    if (inputField.text[inputField.text.Length - 1].Equals('*') ||
                        inputField.text[inputField.text.Length - 1].Equals('-') ||
                        inputField.text[inputField.text.Length - 1].Equals('+') ||
                        inputField.text[inputField.text.Length - 1].Equals('/'))
                    {
                        inputField.text = inputField.text.Substring(0, inputField.text.Length - 1) + txt;
                    }
                    else
                    {
                        inputField.text = inputField.text + txt;
                    }
                }
                else if (inputField.text[inputField.text.Length - 1].Equals(')'))
                {
                    inputField.text = inputField.text + "*" + txt;
                }
                else
                {
                    inputField.text = inputField.text + txt;
                }
            }

            else
            {
                inputField.text = txt;
            }

            break;
        }
    }