示例#1
0
        static bool IsSymmetry(char[] xx)  //判断是否为中心对称串的函数
        {
            int            leng  = xx.Length + 1;
            MyStack <char> exam1 = new MyStack <char>(leng);
            int            a     = xx.Length % 2;

            if (a == 0)
            {
                for (int i = 0; i < xx.Length; i++)
                {
                    if (i == 0 || (i > 0 && xx[i] != exam1.GetTop()))
                    {
                        exam1.Push(xx[i]);
                    }
                    else
                    {
                        exam1.Pop();
                    }
                }
            }
            else
            {
                for (int i = 0; i < xx.Length; i++)
                {
                    if (i == (xx.Length - 1) / 2)
                    {
                        continue;
                    }
                    else if (i == 0 || (i > 0 && xx[i] != exam1.GetTop()))
                    {
                        exam1.Push(xx[i]);
                    }
                    else
                    {
                        exam1.Pop();
                    }
                }
            }
            if (exam1.IsEmpty())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        public string To26System()  //转化为26进制
        {
            string        show = "";
            MyStack <int> exam = new MyStack <int>(Num.Length);

            int[] tt = Num;
            while (!IsZero(NumDivide26(tt)))
            {
                exam.Push(NumMod26(tt));
                tt = NumDivide26(tt);
            }
            exam.Push(NumMod26(tt));
            for (int i = exam.Top; i < exam.Bottom; i++)
            {
                show += ExpressionOf26System(exam.Pop());
            }
            return(show);
        }
示例#3
0
        public double PostExpressionStackCompute()  //后缀表达式求值
        {
            char[] bb = postExpression.ToCharArray();
            int    y  = 0;

            for (int i = 0; i < bb.Length; i++)
            {
                if (bb[i] != '\0')
                {
                    y++;
                }
            }
            char[] aa = new char[y];
            for (int i = 0; i < aa.Length; i++)
            {
                aa[i] = bb[i];
            }
            int leng = aa.Length + 1;
            MyStack <double> save   = new MyStack <double>(leng);
            double           result = 0;

            for (int i = 0; i < aa.Length; i++)
            {
                if (CharJuddging(aa[i]) == "OPD")
                {
                    save.Push(CharToInt(aa[i]));
                }
                else
                {
                    double qq = save.Pop();
                    double ww = save.Pop();
                    save.Push(Operate(aa[i], ww, qq));
                }
            }
            result = save.Pop();
            return(result);
        }