/// <summary> /// 将计算数相加,与其他计算式的相加值一样时舍去 /// </summary> /// <returns></returns> private int[] IsCommon() { string s = ""; LinkBinaryTree <Number> ic = new LinkBinaryTree <Number>(); int[] c = ic.Arithmetic(a[0], a[1], '+', ref s); c = ic.Arithmetic(c, a[2], '+', ref s); c = ic.Arithmetic(c, a[3], '+', ref s); return(c); }
/// <summary> /// 生成一个题目并保存至exercises.txt /// </summary> /// <param name="r">运算数范围</param> /// <returns></returns> public string GetProblem(int r, ref int[] result, ref int [] ic) { a = new int[4][] { new int[] { 0, 1 }, new int[] { 0, 1 }, new int[] { 0, 1 }, new int[] { 0, 1 } }; X = new char[3] { ' ', ' ', ' ' }; //默认为空格,方便判断 //至多有两对括号,且成对出现 //bool b1 = false, b2 = false; //计算式至少有两个运算数,一个运算符,则a,d不为0 string problem = ""; //Random rd = new Random(Guid.NewGuid().GetHashCode()); //int i1 = rd.Next(0, 2); //if(i1==1) //{ // b1 = true; // problem += "("; //} while (a[0][0] == 0) { GetNumber(a[0], r, ref problem); } GetSymbol(a[0][0], ref problem, ref X[0]); GetNumber(a[1], r, ref problem); GetSymbol(a[1][0], ref problem, ref X[1]); GetNumber(a[2], r, ref problem); GetSymbol(a[2][0], ref problem, ref X[2]); while (a[3][0] == 0) { GetNumber(a[3], r, ref problem); } problem += "="; ic = IsCommon(); //Console.WriteLine(problem); TreeNode <Number> sym = new TreeNode <Number>(); GetTree(0, 3, sym); LinkBinaryTree <Number> link = new LinkBinaryTree <Number>(sym.Data); result = link.GetResult(sym, ref problem); return(problem); }