Пример #1
0
 /// <summary>
 /// 单道题的解题
 /// </summary>
 /// <param name="grade"></param>
 /// <returns></returns>
 public static string Branch(string grade)
 {
     if (grade.Contains("/"))
     {
         return(CalculationLogic.ProperFraction(CalculationLogic.ScoreReversePolishType(grade)));
     }
     else
     {
         return(CalculationLogic.ReversePolishType(grade));
     }
 }
Пример #2
0
        /// <summary>
        /// 括号
        /// </summary>
        internal static string bracket(string topic)
        {
            Stack <object> stacknum    = new Stack <object>();
            Stack <string> stacksymbol = new Stack <string>();

            stacksymbol.Push("#");
            while (topic.Length != 0)
            {
                int length = CalculationLogic.Evaluation(topic);
                if (length == 99)
                {
                    stacknum.Push(Convert.ToDouble(topic.Substring(0, topic.Length)));
                    while (stacknum.Count != 1)
                    {
                        var one = stacknum.Pop();
                        var two = stacknum.Pop();
                        stacknum.Push(CalculationLogic.consequence(stacksymbol.Pop(), Convert.ToDouble(two), Convert.ToDouble(one)));
                    }
                    return(stacknum.Peek().ToString());
                }
                if (length != 0)
                {
                    stacknum.Push(Convert.ToDouble(topic.Substring(0, length)));
                    topic = topic.Substring(length, topic.Length - length);
                }
                else if (CalculationLogic.GetOperationLevel(topic.Substring(0, 1)) >
                         CalculationLogic.GetOperationLevel(stacksymbol.Peek()))
                {
                    stacksymbol.Push(topic.Substring(0, 1));
                    topic = topic.Substring(1, topic.Length - 1);
                }
                else
                {
                    var one = stacknum.Pop();
                    var two = stacknum.Pop();
                    stacknum.Push(CalculationLogic.consequence(stacksymbol.Pop(), Convert.ToDouble(two), Convert.ToDouble(one)));
                    stacksymbol.Push(topic.Substring(0, 1));
                    topic = topic.Substring(1, topic.Length - 1);
                }
            }
            return("");
        }
Пример #3
0
        /// <summary>
        /// 题目的生成
        /// </summary>
        /// <param name="QuestionNumber"></param>
        /// <param name="grade"></param>
        /// <returns></returns>
        public static Hashtable ProblemGeneration(string questionNumber, string grade)
        {
            switch (grade)
            {
            case "一年级":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.FirstGrade();
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "二年级":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.SecondGrade();
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "三年级":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.ThreeGrade();
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "四年级":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.FourGrade();
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "五年级":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.FiveGrade();
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "六年级":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.SixGrade();
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "整数":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.RandomDigit(0, 1);
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "小数":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.RandomDigit(1, 2);
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;

            case "分数":
                for (int i = 0; i < int.Parse(questionNumber); i++)
                {
                    try
                    {
                        string title = RandomTopic.RandomDigit(2, 3);
                        titleHash.Add(title, CalculationLogic.branch(title));
                    }
                    catch
                    {
                        i--;
                    }
                }
                break;
            }
            return(titleHash);
        }