Exemplo n.º 1
0
        public void Add( BigInt value )
        {
            int aCount = _digits.Count;
             int bCount = value._digits.Count;
             int carry = 0;
             for ( int i = 0; i < System.Math.Max( aCount, bCount ); i++ )
             {
            int a = 0;
            int b = 0;
            if ( aCount > i )
               a = _digits[i];
            if ( bCount > i )
               b = value._digits[i];
            int sum = a + b + carry;
            int d;
            carry = System.Math.DivRem(sum, 10, out d);

            if ( aCount > i )
               _digits[i] = d;
            else
               _digits.Add(d);
             }
             if ( carry > 0 )
            _digits.Add(carry);
        }
Exemplo n.º 2
0
 public void TestDefaultConstructor()
 {
     BigInt bi = new BigInt();
      Assert.AreEqual( "0", bi.ToString() );
 }
Exemplo n.º 3
0
 public void TestConstructor( string value, string expected )
 {
     BigInt bi = new BigInt( value );
      Assert.AreEqual( expected, bi.ToString() );
 }
Exemplo n.º 4
0
 public void TestAdd( string a, string b, string expected )
 {
     BigInt bi = new BigInt( a );
      bi.Add( b );
      Assert.AreEqual( expected, bi.ToString() );
 }
Exemplo n.º 5
0
 public void Add( string value )
 {
     BigInt i = new BigInt( value );
      Add(i);
 }
Exemplo n.º 6
0
 public long Solve()
 {
     try
      {
     BigInt sum = new BigInt();
     foreach ( string number in _numbers )
     {
        sum.Add(number);
     }
     string value = sum.ToString();
     value = value.Substring( 0, 10 );
     return long.Parse( value );
      }
      catch ( Exception e )
      {
     Console.WriteLine( e );
      }
      return 0;
 }