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(); }
public MyBigInteger(MyBigInteger bigInt) : this(bigInt.Number) { }
protected virtual MyBigInteger BuildBigInteger(int[] module, char oct) { int pos = 0; StringBuilder builder = new StringBuilder(); for (int i = 0; i < module.Length; i++, pos++) { if (module[i] != 0) break; } if (oct == MyBigInteger.negativeOct) builder.Append(MyBigInteger.negativeOct); for (int i = pos; i < module.Length; i++) builder.Append(module[i]); MyBigInteger b = new MyBigInteger(); b.Number = builder.ToString(); return b; }
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); }
public MyBigInteger Sub(MyBigInteger bigInt) { if (Octothorpe == MyBigInteger.positiveOct && bigInt.Octothorpe == MyBigInteger.negativeOct) { MyBigInteger tmp = BuildBigInteger(bigInt.Module, MyBigInteger.positiveOct); return Sum(tmp); } else if (Octothorpe == MyBigInteger.negativeOct && bigInt.Octothorpe == MyBigInteger.positiveOct) { MyBigInteger tmp1 = BuildBigInteger(Module, MyBigInteger.positiveOct); MyBigInteger tmp2 = tmp1.Sum(bigInt); return BuildBigInteger(tmp2.Module, MyBigInteger.negativeOct); } else if (Octothorpe == MyBigInteger.negativeOct && bigInt.Octothorpe == MyBigInteger.negativeOct) { MyBigInteger tmp1 = BuildBigInteger(Module, MyBigInteger.positiveOct); MyBigInteger tmp2 = BuildBigInteger(bigInt.Module, MyBigInteger.positiveOct); return tmp2.Sub(tmp1); } 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; if (CompareTo(bigInt) > 0) { for (int i = MyBigInteger.SIZE - 1; i >= 0; i--) { if ((bufTmp1[i] + inMind) >= bufTmp2[i]) { buff[i] = bufTmp1[i] - bufTmp2[i] + inMind; inMind = 0; } else { buff[i] = bufTmp1[i] + 10 - bufTmp2[i] + inMind; inMind = -1; } } } else if (CompareTo(bigInt) < 0) { for (int i = MyBigInteger.SIZE - 1; i >= 0; i--) { if ((bufTmp2[i] + inMind) >= bufTmp1[i]) { buff[i] = bufTmp2[i] - bufTmp1[i] + inMind; inMind = 0; } else { buff[i] = bufTmp2[i] + 10 - bufTmp1[i] + inMind; inMind = -1; } } oct = MyBigInteger.negativeOct; } return BuildBigInteger(buff, oct); }
public int CompareTo(MyBigInteger bigInt) { int result = 0; if (bigInt.Octothorpe == MyBigInteger.negativeOct && Octothorpe == MyBigInteger.positiveOct) return 1; else if (Octothorpe == MyBigInteger.negativeOct && bigInt.Octothorpe == MyBigInteger.positiveOct) return -1; else if (Module.Length > bigInt.Module.Length) return 1; else if (Module.Length < bigInt.Module.Length) return -1; else if (Module.Length == bigInt.Module.Length) { for (int i = 0; i < Module.Length; i++) { if (Module[i] > bigInt.Module[i]) return 1; else if (Module[i] < bigInt.Module[i]) return -1; } } return result; }