Exemplo n.º 1
0
Arquivo: App.cs Projeto: ipzPZ121/OOP
        public static void Main(string[] args)
        {
            using(ArrayReader arrReader = new ArrayReader(new char[]{'H', 'e', 'l', 'l', 'o', '\n', 'w', 'o', 'r', 'l', 'd', '\r', '\n'})) {
                string text4 = arrReader.ReadLine();
                Console.WriteLine(text4);
                string text5 = arrReader.ReadLine();
                Console.WriteLine(text5);
                string text6 = arrReader.ReadToEnd();
                Console.WriteLine(text6);
            }

            Console.WriteLine();

            App.SortString("file1.txt", "out.txt");

            Console.WriteLine();

            char[] ch1 = {'H', 'e', 'l', 'l', 'o', '\n', 'w', 'o', '\r', 'r', 'l', 'd', ' ', 'a', 'n', 'd', ' '};
            char[] ch2 = {'H', 'e', 'l', 'l', 'o', '\n', 'w', 'o', 'r', 'l', 'd'};
            char[] ch3 = null;
            using(ArrayWriter tWr = new ArrayWriter()) {
                tWr.Write(ch1);
                tWr.WriteLine(ch2);
                Console.WriteLine(tWr.Text);
                Console.WriteLine();
                try {
                 tWr.Write(ch3);
                } catch(MyException myExp) {
                    Console.WriteLine(myExp.Message);
                }

            }

            Console.WriteLine();

            MyBigInteger bigInt1 = new MyBigInteger("45647546768465354");
            MyBigInteger bigInt2 = new MyBigInteger("125646545634543543354534354343");
            MyBigInteger bigInt3 = bigInt1.Sum(bigInt2);
            Console.WriteLine(bigInt3.Number);
            Console.WriteLine();
            MyBigInteger bigInt4 = bigInt1.Sub(bigInt2);
            Console.WriteLine(bigInt4.Number);

            Console.WriteLine();
        }
Exemplo n.º 2
0
        public MyBigInteger Sum(MyBigInteger bigInt)
        {
            if (Octothorpe == MyBigInteger.positiveOct && bigInt.Octothorpe == MyBigInteger.negativeOct) {
                MyBigInteger tmp = BuildBigInteger(bigInt.Module, MyBigInteger.positiveOct);
                return Sub(tmp);
            } else if (Octothorpe == MyBigInteger.negativeOct && bigInt.Octothorpe == MyBigInteger.positiveOct) {
                MyBigInteger tmp = BuildBigInteger(Module, MyBigInteger.positiveOct);
                return bigInt.Sub(tmp);
            } else if (Octothorpe == MyBigInteger.negativeOct && bigInt.Octothorpe == MyBigInteger.negativeOct) {
                MyBigInteger tmp = BuildBigInteger(bigInt.Module, MyBigInteger.positiveOct);
                return Sub(tmp);
            }

            int[] buff = new int[MyBigInteger.SIZE];
            int[] bufTmp1;
            int[] bufTmp2;
            InitBuffers(Module, bigInt.Module, out bufTmp1, out bufTmp2, MyBigInteger.SIZE);

            int inMind = 0;
            char oct = MyBigInteger.positiveOct;

            for (int i = MyBigInteger.SIZE - 1; i >= 0; i--) {
                if ((bufTmp1[i] + bufTmp2[i] + inMind) < 10) {
                    buff[i] = bufTmp1[i] + bufTmp2[i] + inMind;
                    inMind = 0;
                } else {
                    buff[i] = (bufTmp1[i] + bufTmp2[i] + inMind) % 10;
                    inMind = (bufTmp1[i] + bufTmp2[i] + inMind) / 10;
                }
            }

            return BuildBigInteger(buff, oct);
        }